编程语言
首页 > 编程语言> > python时间python时间字符串与时间戳相互转换字符串与时间戳相互转换

python时间python时间字符串与时间戳相互转换字符串与时间戳相互转换

作者:互联网

import time

year = 2020
month = 1
day = 20

dateStr = "{}-{}-{}".format(year, month, day)
print(dateStr)

timeArray = time.strptime(dateStr, "%Y-%m-%d")
# 转换为时间戳:
timeStamp = int(time.mktime(timeArray))

print(timeStamp)

timeArray = time.localtime(timeStamp)
timeStr = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
print(timeStr)

标签:-%,python,timeStamp,timeStr,timeArray,print,时间,time,字符串
来源: https://www.cnblogs.com/WebLinuxStudy/p/14385363.html