time模块-常见使用

查看一下时间戳2000000000表示的年月日

代码如下:

import time
struct_t=time.localtime(2000000000)
print(struct_t)
print(time.strftime('%Y-%m-%d',struct_t))

运行结果:

time.struct_time(tm_year=2033, tm_mon=5, tm_mday=18, tm_hour=11, tm_min=33, tm_sec=20, tm_wday=2, tm_yday=138, tm_isdst=0)
2033-05-18

 

将2018-8-8时间格式转化为时间戳时间

import time
t= time.strptime('2018-8-8','%Y-%m-%d')
print(time.mktime(t))

运行结果:

1533657600.0

 

posted @ 2021-07-01 16:19  社会你玲姐  阅读(47)  评论(0)    收藏  举报