Python 日期与时间戳 互转
import time #日期转时间戳 tss1 = '2020-12-28 00:00:00' timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S") # 转为时间数组 # 转为时间戳 timeStamp = int(time.mktime(timeArray)) print("日期转时间戳为:") print(timeStamp) #秒级 print(int(round(timeStamp * 1000)))#毫秒级 ------------------------------------------------ #使用time 将时间戳转化为日期 tst = timeStamp timeArray = time.localtime(tst) timeStampTodate = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) print("时间戳转日期为:") print(timeStampTodate)