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

转载自:https://blog.csdn.net/qq_25231683/article/details/120016771

你可能感兴趣的:(Python,python,时间戳,转换)