一、time模块
import time
# 生成timestamp
time.time()
# 1477471508.05
#struct_time to timestamp
time.mktime(time.localtime())
#生成struct_time
# timestamp to struct_time 本地时间
time.localtime()
time.localtime(time.time())
# time.struct_time(tm_year=2016, tm_mon=10, tm_mday=26, tm_hour=16, tm_min=45, tm_sec=8, tm_wday=2, tm_yday=300, tm_isdst=0)
# timestamp to struct_time 格林威治时间
time.gmtime()
time.gmtime(time.time())
# time.struct_time(tm_year=2016, tm_mon=10, tm_mday=26, tm_hour=8, tm_min=45, tm_sec=8, tm_wday=2, tm_yday=300, tm_isdst=0)
#format_time to struct_time
time.strptime(‘2011-05-05 16:37:06′,’%Y-%m-%d %X’)
# time.struct_time(tm_year=2011, tm_mon=5, tm_mday=5, tm_hour=16, tm_min=37, tm_sec=6, tm_wday=3, tm_yday=125, tm_isdst=-1)
#生成format_time
#struct_time to format_time
time.strftime(“%Y-%m-%d %X”)
time.strftime(“%Y-%m-%d %X”,time.localtime())
# 2016-10-26 16:48:41
#生成固定格式的时间表示格式
time.asctime(time.localtime())
time.ctime(time.time())
# Wed Oct 26 16:45:08 2016
属性 值
tm_year(年) 比如2011
tm_mon(月)1 – 12
tm_mday(日)1 – 31
tm_hour(时)0 – 23
tm_min(分)0 – 59
tm_sec(秒)0 –