时间戳转换为日期字符串
    Args:
        ts: 待转换的时间戳
        dt_format: 目标日期字符串格式

    Returns: 日期字符串
333541
def ts_to_dt_str(ts, dt_format='%Y-%m-%d %H:%M:%S'):
    
    return datetime.datetime.fromtimestamp(int(ts)).strftime(dt_format)
454187
def _dtfromtimestamp(timestamp):
    
    try:
        return datetime.datetime.fromtimestamp(timestamp)
    except OSError:
        timestamp -= time.timezone
        dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
        if _isdst(dt):
            timestamp += 3600
            dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=timestamp)
        return dt
265281
def format_date(cls, timestamp):
        
        if not timestamp:
            raise DateTimeFormatterException('timestamp must a valid string {}'.format(timestamp))

        return timestamp.strftime(cls.DATE_FORMAT)
653833
def to_ts(s):
        

        # Strip TZ portion if present
        m = Nginx.DATE_FMT.match(s)
        if m:
            s = m.group(1)
            delta = timedelta(seconds=int(m.group(3)) * (-1 if m.group(2) == '-' else 1)) # Offset from GMT
        else:
            delta = timedelta(seconds=0)
        dt = datetime.strptime(s, "%d/%b/%Y:%H:%M:%S")
        dt += delta
        return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
185930
def tgread_date(self):
        
        value = self.read_int()
        if value == 0:
            return None
        else:
            return datetime.fromtimestamp(value, tz=timezone.utc)
369858
def local_rfcformat(dt):
    
    weekday = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][dt.weekday()]
    month = [
        'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
        'Oct', 'Nov', 'Dec',
    ][dt.month - 1]
    tz_offset = dt.strftime('%z')
    return '%s, %02d %s %04d %02d:%02d:%02d %s' % (
        weekday, dt.day, month,
        dt.year, dt.hour, dt.minute, dt.second, tz_offset,
    )
265625
def format_timestamp(timestamp):
        
        tz_info = tz.tzutc()
        return datetime.fromtimestamp(timestamp, tz=tz_info).strftime("%Y-%m-%dT%H:%M:%S.000Z")
1118724
def formatted_time(self, fmt: str = '') -> str:
        
        time_obj = self.time()

        if not fmt:
            fmt = self._data['formats'].get('time')
        return time_obj.strftime(fmt)
1024718
def ctime(self, fpath=None):
        
        return dtformat(
            datetime.datetime.utcfromtimestamp(
                os.path.getctime(fpath or self.fpath)))
1161540
def timestamp_to_datetime(cls, dt, dt_format=DATETIME_FORMAT):
        """"""
        return cls.convert_datetime(cls.get_datetime(dt), dt_format=dt_format)
412377
def datetime_to_timestamp(dt):
    

    epoch = datetime.utcfromtimestamp(0).replace(tzinfo=UTC)
    return (dt - epoch).total_seconds()
778944
static public String getFormattedTime(long dt, String format, boolean isTime)
    {
        String ret = "";
        SimpleDateFormat df = null;

        try
        {
            if(dt > 0)
            {
                df = formatPool.getFormat(format);
                if(isTime)
                    df.setTimeZone(DateUtilities.getCurrentTimeZone());
                else
                    df.setTimeZone(DateUtilities.defaultTZ);
                ret = df.format(new Date(dt));
            }
        }
        catch(Exception e)
        {
        }

        if(df != null)
            formatPool.release(df);

        return ret;
    }
1312517
def get_date_info(value):
    
    fmt = _get_date_format(value)
    dt_value = _datetime_obj_factory(value, fmt)
    return dt_value, fmt
443167
public static String dateSub(long ts, int days, TimeZone tz) {
		ZoneId zoneId = tz.toZoneId();
		Instant instant = Instant.ofEpochMilli(ts);
		ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId);
		long resultTs = zdt.minusDays(days).toInstant().toEpochMilli();
		return dateFormat(resultTs, DATE_FORMAT_STRING, tz);
	}
1149233
def _get_date_time_format(dt_string):
    '''
    
    '''
    valid_formats = [
        '%I:%M:%S %p',
        '%I:%M %p',
        '%H:%M:%S',
        '%H:%M',
        '%Y-%m-%d',
        '%m-%d-%y',
        '%m-%d-%Y',
        '%m/%d/%y',
        '%m/%d/%Y',
        '%Y/%m/%d'
    ]
    for dt_format in valid_formats:
        try:
            datetime.strptime(dt_string, dt_format)
            return dt_format
        except ValueError:
            continue
    return False
801859
def _get_date_time_format(dt_string):
    '''
    
    '''
    valid_formats = [
        '%H:%M',
        '%H:%M:%S',
        '%m:%d:%y',
        '%m:%d:%Y',
        '%m/%d/%y',
        '%m/%d/%Y'
    ]
    for dt_format in valid_formats:
        try:
            datetime.strptime(dt_string, dt_format)
            return dt_format
        except ValueError:
            continue
    msg = 'Invalid Date/Time Format: {0}'.format(dt_string)
    raise SaltInvocationError(msg)
741095
def format_day(
        self, date: datetime.datetime, gmt_offset: int = 0, dow: bool = True
    ) -> bool:
        
        local_date = date - datetime.timedelta(minutes=gmt_offset)
        _ = self.translate
        if dow:
            return _("%(weekday)s, %(month_name)s %(day)s") % {
                "month_name": self._months[local_date.month - 1],
                "weekday": self._weekdays[local_date.weekday()],
                "day": str(local_date.day),
            }
        else:
            return _("%(month_name)s %(day)s") % {
                "month_name": self._months[local_date.month - 1],
                "day": str(local_date.day),
            }