The time and datetime module

The time and datetime module

Import Time
 Print (time.clock ())
 Print (time.process_time ()) # measurement processor computation time 
Print (time.altzone) # Returns utc time difference, in seconds 
Print (that time.asctime ()) # return time format 
Print (time.localtime ()) # returns the local time of the struct time objects 
Print (time.gmtime (time.time ())) # returns struc time utc time difference with China local time of 8 hours, eight districts in East China . 
Print (that time.asctime (time.localtime ())) # return time format 
Print (time.ctime ()) # return time format, the same winding




string_2_struct = the time.strptime ( " 2019/12/19 " , " % the Y /% m /% D " )   # convert the date into a product struct time format character 
Print (string_2_struct)
string_2_stamp = time.mktime (string_2_struct) # The struct time image into a timestamp

Print (time.gmtime (the time.time ())) # converts UTC time stamp format to struct_time 
Print (The time.strftime ( " % D%% Y-M-% H:% M:% S " , time.gmtime ())) # will be transferred to the specified format UTC struct_time string format ######## 2019-12-19 14:53:37


# Operation time (add or subtract) 
Import   datetime
 print (datetime.datetime.now ())   # Returns the current time 
print (datetime.date.fromtimestamp (the time.time ())) # The date stamp format directly converted into 
print (datetime.datetime.now () + the datetime.timedelta (. 3)) # current time plus 3 days 
Print (datetime.datetime.now () + the datetime.timedelta (-3)) # current time minus three days 
Print (datetime. DateTime.Now () + the datetime.timedelta (=. 3 hours)) # current time plus 3 hours 
Print (datetime.datetime.now () + the datetime.timedelta (= 30 minutes)) # current time plus 30 minutes


c_time = datetime.datetime.now ()
 Print (c_time.replace (=. 3 minute, hour = 2)) # replace the time to 2:03 minutes.



Print results
3e-07
0.109375
-32400
Thu Dec 19 23:32:52 2019
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=23, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
Thu Dec 19 23:32:52 2019
Thu Dec 19 23:32:52 2019
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=353, tm_isdst=-1)
time.struct_time(tm_year=2019, tm_mon=12, tm_mday=19, tm_hour=15, tm_min=32, tm_sec=52, tm_wday=3, tm_yday=353, tm_isdst=0)
2019-12-19 15:32:52
2019-12-19 23:32:52.735813
2019-12-19
2019-12-22 23:32:52.735813
2019-12-16 23:32:52.735813
2019-12-20 02:32:52.735813
2019-12-20 00:02:52.735813
2019-12-19 02:03:52.735813

Guess you like

Origin www.cnblogs.com/kezi/p/12070907.html