One, Time module
1, Time.sleep (5) #等待5秒钟
# !usr/bin/env python # -*-coding:utf-8-*- Import Time Print ('start to sleep .... ' ) Time.sleep (5) # wait 5 seconds for print('wake up ..... ')
#!usr/bin/env python#-*-coding:utf-8-*-Import TimePrint(Time.clock ())#returns processor Time, 3.3 deprecatedPrint(Time.process_time ())#returns processor Time, 3.3 deprecatedPrint(Time.time ())#return timestamp, January 1, 1970 0:00 to now how many seconds, all system timestamps are timed from that timePrint(Time.ctime (Time.time ()))#Converts a timestamp into a string, Thu Feb 10:10:20Print(Time.ctime (Time.time () -24*60*60))#Convert time to string, yesterday at this time, Thu Feb 10:10:20Print(Time.gmtime (Time.time ()))#returns the Time.struct_time object, which can be extracted from month to day secondsPrint(Time.localtime (Time.time ()))#returns the Time.struct_time object, which displays the local time, which can be extracted by the datePrint(Time.mktime (Time.localtime (Time.time ())))#Converts Time.struct_time objects to timestamps, in contrast to the localtime functionPrint(Time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (Time.time ())))#Convert a Time.struct_time object to a string formatPrint(Time.strptime ('2017-2-16 11:40:27','%y-%m-%d%h:%m:%s'))#Convert A string to a Time.struct_time object
#!usr/bin/env python#-*-coding:utf-8-*-#usage of time.gmtime ()#usage of time.localtime ()ImportTimetime_object=Time.gmtime (Time.time ())Print(Time_object)#time.struct_time (tm_year=2017, tm_mon=2, tm_mday=16,#tm_hour=2, tm_min=35, tm_sec=54, tm_wday=3, tm_yday=47, tm_isdst=0)Time_str ='%s-%s-%s%s:%s:%s'%(time_object.tm_year,time_object.tm_mon,time_object.tm_mday,time_object.tm_hour,time_object.tm_min,time_ OBJECT.TM_SEC)Print(TIME_STR)#2017-2-16 2:45:26 GMT
"Python Route 25" module