Time Module
Time ()--return current time in seconds since the Epoch as a float
Clock ()--return CPU time since process start as a float
Sleep ()--delay for a number of seconds given as a float
Gmtime ()--convert seconds since Epoch to UTC tuple
LocalTime ()--convert seconds since Epoch to local time tuple
Asctime ()--Convert time tuple to string
CTime ()--convert time in seconds to string
Mktime ()--convert local time tuple to seconds since Epoch
Strftime ()--Convert time tuple to string according to format specification
Strptime ()--parse string to time tuple according to format specification
Tzset ()--Change the local timezone
Time ()--return current time in seconds since the Epoch as a float
Sleep ()--delay for a number of seconds given as a float
Print ( time.time ())print (time.sleep (3))print (Time.time ()) Results: 1463616112.13201None1463616115.132182
Gmtime ()--convert seconds since Epoch to UTC tuple
Print (time.gmtime (1463616204.311283))print (Time.gmtime (Time.time ())) Results: time.struct_ Time (Tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=3, tm_sec=24, tm_wday=3, tm_yday=140, tm_isdst=0) Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=4, tm_sec=15, tm_wday=3, tm_yday=140, tm_ isdst=0)
LocalTime ()--convert seconds since Epoch to local time tuple
Print (Time.localtime ())print (time.localtime (1463616204.311283)) Results: Time.struct_time ( Tm_year=2016, tm_mon=5, tm_mday=19, Tm_hour=8, tm_min=6, tm_sec=26, tm_wday=3, tm_yday=140, tm_isdst=0) Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=19, Tm_hour=8, tm_min=3, tm_sec=24, tm_wday=3, tm_yday=140, tm_ isdst=0)
Asctime ()--Convert time tuple to string
Print ( time.time ())print ( time.asctime ())print (Time.asctime ( Time.localtime (1463616204.311283)) results:1463616842.65579408:14:0219 08:03:24 2016
def strftime (format, P_tuple=none):
A = Time.localtime (1363616204.311283)print ( a)print (time.strftime (' %y%m%d ' , a)) Results: Time.struct_time (tm_year=2013, tm_mon=3, tm_mday=18, tm_hour=22, tm_min=16, tm_sec=44, tm_wday=0, tm_yday=77, tm_isdst=0)20130318
Def strptime (string, format):
Print (Time.strptime ("20130318", "%y%m%d"))
A = Time.strptime ("20130318", "%y%m%d")
Print (Type (a))
Print (A.tm_mday)
Time.struct_time (tm_year=2013, tm_mon=3, tm_mday=18, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=77, Tm_isdst=-1 )
<class ' Time.struct_time ' >
18
def mktime (p_tuple): Print (Time.gmtime ()) Print (Time.mktime (Time.gmtime ())) Results: Time.struct_time (tm_year=2016, tm_mon=5, tm_mday=19, tm_hour=0, tm_min=47, Tm_sec=21, Tm_wday=3, tm_yday=140, tm_isdst=0)1463590041.0
Python Time and datetime modules