凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

python 时间格式时间戳互转

2021-06-08 python 1193
import time


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


format_time = '2021-07-01 00:00:00'
# 时间
ts = time.strptime(format_time, "%Y-%m-%d %H:%M:%S")
# 格式化时间转时间戳
s = int(time.mktime(ts))
print(s)

ts = time.localtime(s)
print(time.strftime("%Y-%m-%d %H:%M:%S",ts))


文章评论

0条评论