datetime:时间戳转换

2017-11-22  本文已影响0人  Lacia

将时间戳转换为年月日时分秒格式:

import datetime
timeStamp = 1511169651
dateArray = datetime.datetime.utcfromtimestamp(timeStamp)

print dateArray
otherStyleTime = dateArray.strftime("%Y-%m-%d %H:%M:%S")

print otherStyleTime

将年月日时分秒格式转换为时间戳:

import time

a = "2017-11-14 13:30:00"


timeArray = time.strptime(a, "%Y-%m-%d %H:%M:%S")

timeStamp = int(time.mktime(timeArray))

print timeStamp
上一篇下一篇

猜你喜欢

热点阅读