import time
1. time.gmtime() 显示当前structtime,格林时间
>>> import time
>>> time.gmtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=12, tm_min=48, tm_s
ec=25, tm_wday=6, tm_yday=73, tm_isdst=0)
>>> a = time.gmtime()
>>> print(a.tm_year)
2016
2. time.localtime() 显示当前本地时间,structime
>>> time.localtime()
time.struct_time(tm_year=2016, tm_mon=3, tm_mday=13, tm_hour=20, tm_min=51, tm_s
ec=35, tm_wday=6, tm_yday=73, tm_isdst=0)
3. time.time() 当前系统时间戳,以毫秒为单位的时间,从1970年到现在
>>> time.time()
1457873653.96087
4. time.strftime("%Y-%m-%d %H:%M:%S") 将strucktime格式化输出
>>> time.strftime("%Y-%m-%d %H:%M:%S")
'2016-03-13 20:58:49'
>>> time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
'2016-03-13 13:05:55'
5. time.mktime() 将strucktime变成时间戳
>>> time.mktime(time.localtime())
1457874273.0
>>>
6. time.strptime() 转换成strucktime格式
>>> time.strptime("2015-04-03", "%Y-%m-%d")
time.struct_time(tm_year=2015, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=
0, tm_wday=4, tm_yday=93, tm_isdst=-1)
7. time.ctime() 系统格式输出当前系统时间,也可用于将时间戳转换成系统格式
>>> time.ctime()
'Sun Mar 13 21:10:58 2016'
>>> time.ctime(1457874763.685563)
'Sun Mar 13 21:12:43 2016'