首页 > 代码库 > Day6_time模块

Day6_time模块

TIME模块:

print(time.time())  #指的是从1970年到现在的秒数

print(time.strftime(‘%Y-%m-%d %X‘))  #指定特定的格式输出时间

print(time.localtime())  #得到的是一个对象,如果想要看下面的子模块,看哪个模块就在后边加上(.模块)就好,一定不要忘了点

print(time.localtime())
#time.struct_time(tm_year=2017, tm_mon=8, tm_mday=11, tm_hour=9, tm_min=39, tm_sec=21, tm_wday=4, tm_yday=223, tm_isdst=0)

 print(time.gmtime())  #看的是UTC标准时间

 

时间之间的相互转化:

print(time.localtime(1502416311.4879167))
print(time.gmtime(1502416311.4879167))
print(time.mktime(time.localtime(1502416311.4879167)))
print(time.strftime(‘%Y‘,time.gmtime()))
print(time.strptime(‘2017-03-01‘,‘%Y-%m-%d‘))

显示结果:
time.struct_time(tm_year=2017, tm_mon=8, tm_mday=11, tm_hour=9, tm_min=51, tm_sec=51, tm_wday=4, tm_yday=223, tm_isdst=0)
time.struct_time(tm_year=2017, tm_mon=8, tm_mday=11, tm_hour=1, tm_min=51, tm_sec=51, tm_wday=4, tm_yday=223, tm_isdst=0)
1502416311.0
2017
time.struct_time(tm_year=2017, tm_mon=3, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=60, tm_isdst=-1)

 

技术分享

 

Day6_time模块