毫秒时间戳转换

it2022-05-05  152

注:时间戳——格式化时间 不能直接相互转换,需要转为时间元祖进行过渡

毫秒时间戳13位,秒时间戳10位

毫秒时间戳:

timeTemp = '1563443717288'

截取字符串 :

# 最后三位的毫秒数 288 lMillisecond = str(timeTemp)[10:13] # 获取秒的时间戳 1563443717288 second = str(timeTemp)[0:10] # 转换为元祖 timeArray = time.localtime(int(second)) # 转换后的时间 2019--07--18 otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray) # 转换后的时间和毫秒结合 2019--07--18 17:55:17.288 otherStyleTime = otherStyleTime + '.' + lMillisecond print(otherStyleTime)

获取当前系统毫秒级时间(与时间戳没关系)

time_end = datetime.datetime.now().strftime('%H:%M:%S.%f') print(time_end)

 


最新回复(0)