时间戳
程序员文章站
2022-07-03 15:00:56
...
import time
from datetime import datetime
now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
timeArray = time.strptime(now, "%Y-%m-%d %H:%M:%S")
print(timeArray, type(timeArray))
# time.struct_time(tm_year=2019, tm_mon=2, tm_mday=23, tm_hour=15, tm_min=26, tm_sec=49, tm_wday=5, tm_yday=54, tm_isdst=-1) <class 'time.struct_time'>
print(time.mktime(timeArray))
# 1550906883.0
# 快所获得时间戳
print(time.time())
# 1550906883.9737751
print(int(time.time()))
# 1550906883
# 时间戳转换成时间
timestruck = 1550905859
st = time.localtime(timestruck)
print(st)
# time.struct_time(tm_year=2019, tm_mon=2, tm_mday=23, tm_hour=15, tm_min=10, tm_sec=59, tm_wday=5, tm_yday=54, tm_isdst=0)
print(time.strftime("%Y-%m-%d %H:%M:%S", st))
转载于:https://www.jianshu.com/p/aa20419c2b65
上一篇: 宋理宗赵昀的头颅为什么会被做成酒杯?朱元璋的做法让人敬佩
下一篇: zabbix监控部署