def timestamp2Datetime(timeStamp :int) :
'''
时间戳转日期时间
例如 1557502800转换成 2019-05-10 23:40:00
'''
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
return otherStyleTime
def timestamp2Date(timeStamp :int) :
'''
时间戳转日期
例如 1557502800转换成 2019-05-10
'''
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d", timeArray)
return otherStyleTime
print(timestamp2Datetime(1557502800))
print(timestamp2Date(1557502800))
def _datetime2timestamp(self, datetime_str='2020-01-31 00:00:00', convert_to_utc=True):
dt = datetime.datetime.strptime(datetime_str,'%Y-%m-%d %H:%M:%S')
if convert_to_utc:
dt = dt + datetime.timedelta(hours=8)
return int(datetime.datetime.timestamp(dt))
from: https://zhuanlan.zhihu.com/p/101978992
No comments:
Post a Comment