Common functions
- Time.time () returns the current timestamp
>>> time.time()1465370844.096474
- Time.ctime () returns the time character of this format ' Wed June 8 15:27:48 2016 ', showing the current time. You can also convert timestamps
>>> time.ctime()'Wed Jun 8 15:27:48 2016'>>> time.ctime(time.time()-86400)'Tue Jun 7 15:29:36 2016'
- Time.gmtime converts the timestamp to the Struct_time format, which shows the time in Greenwich 0 time zone
>>> time.gmtime()time.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=7, tm_min=34, tm_sec=28, tm_wday=2, tm_yday=160, tm_isdst=0)>>> time.gmtime(time.time() - 86400)time.struct_time(tm_year=2016, tm_mon=6, tm_mday=7, tm_hour=7, tm_min=34, tm_sec=41, tm_wday=1, tm_yday=159, tm_isdst=0)
- Time.localtime converting the current system timestamp to struct_time format
>>> time.localtime()time.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=15, tm_min=35, tm_sec=33, tm_wday=2, tm_yday=160, tm_isdst=0)>>> time.localtime(time.time() - 86400)time.struct_time(tm_year=2016, tm_mon=6, tm_mday=7, tm_hour=15, tm_min=37, tm_sec=10, tm_wday=1, tm_yday=159, tm_isdst=0)
- Time.mktime struct_time format back to timestamp
>>> now = time.localtime()>>> nowtime.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=15, tm_min=38, tm_sec=28, tm_wday=2, tm_yday=160, tm_isdst=0)>>> time.mktime(now)1465371508.0
- Time.strftime convert the Struct_time format to the specified string format
>>> now = time.localtime()>>> nowtime.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=15, tm_min=38, tm_sec=28, tm_wday=2, tm_yday=160, tm_isdst=0)>>> last = time.localtime(time.time() - 86400)>>> lasttime.struct_time(tm_year=2016, tm_mon=6, tm_mday=7, tm_hour=15, tm_min=40, tm_sec=23, tm_wday=1, tm_yday=159, tm_isdst=0)>>> time.strftime("%Y-%m-%d %H:%M:%S",last)'2016-06-07 15:40:23'>>> time.strftime("%Y-%m-%d %H:%M:%S",now)'2016-06-08 15:38:28'
- Time.strptime Convert a custom time format string to struct_time format
>>> time.strptime("2016-06-08","%Y-%m-%d")time.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=160, tm_isdst=-1)>>> time.strptime("2016-06-08 15:50:44","%Y-%m-%d %H:%M:%S")time.struct_time(tm_year=2016, tm_mon=6, tm_mday=8, tm_hour=15, tm_min=50, tm_sec=44, tm_wday=2, tm_yday=160, tm_isdst=-1)
- Time.sleep pause time, similar to the Shell's sleep ()