time datetime

时间有三种格式:struct_time(tuple) 时间戳 时间字符串

time.time() #距1970到现在的时间戳 多少秒

将时间戳转为struct_time: time.gtime(time.time())  为UTC时间 time.localtime()为UTC时间 两者参数为时间戳(秒)

x=time.localtime()#time.struct_time(tm_year=2017, tm_mon=4, tm_mday=3, tm_hour=12, tm_min=23, tm_sec=18, tm_wday=0, tm_yday=93, tm_isdst=0)

取struct_time中的年月日等结果 x.tm_year  x.tm_yday

将struct_time转为字符串时间time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()) time.strftime('时间格式',struct_time)

将字符串时间格式转为struct_time  time.strptime('2017-04-04 12:23:12','%Y-%m-%d %H:%M:%S')

将时间戳转为字符串:time.ctime(time.time())参数为时间戳

将struct_time转为时间格式字符串:time.asctime()参数为struct_time

原文地址:https://www.cnblogs.com/howhy/p/6663615.html