Unix 时间戳根据精度的不同,有 10 位(秒级),13 位(毫秒级),16 位(微妙级)和 19 位(纳秒级)
python 毫秒级时间,时间戳转换如下:
时间转时间戳:
import time
from datetime import datetime
timestr = '2019-01-14 15:22:18.123'
datetime_obj = datetime.strptime(timestr, "%Y-%m-%d %H:%M:%S.%f")
obj_stamp = int(time.mktime(datetime_obj.timetuple()) * 1000.0 + datetime_obj.microsecond / 1000.0)
时间戳转时间:
import time
def timeStamp(timeNum):
timeStamp = float(timeNum/1000)
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print otherStyleTime
来源:oschina
链接:https://my.oschina.net/zhenggao/blog/4957287