1, time is the processing time of the module, summarize here what common functions to achieve.
. 1 Import time T AS 2 . 3 Print (the dir (T)) # See methods at the time module . 4 . 5 Print (t.time ()) # timestamp is obtained (start timing 1970) . 6 Print (t.localtime () ) # Get local current time, return is struct_time format (tm_year = 2020, tm_mon =. 1, tm_mday =. 6, tm_hour = 0, tm_min = 12 is, tm_sec = 42 is, tm_wday = 0, tm_yday =. 6, the tm_isdst = 0) . 7 Print (t.ctime ()) # F acquires the current date time format string . 8 Print (t.strftime ( ' % Y-M-%%% M-H-D-% S% ' , t.localtime ())) # format display time . 9 Print (t.strftime ( 'Y- M-% D%%% X ' , t.localtime ())) 10 . 11 Print (t.ctime (t.time ())) # timestamp into a string of time 12 is Print (t.localtime (T .time ())) # timestamp format is converted to struct_time time
2, datetime module date and times in both simple and complex ways.
While date and time arithmetic, focusing on the realization of more efficient processing and formatting output.
. 1 Import datetime 2 Import Time T AS . 3 from datetime Import DATE . 4 . 5 . 6 Print (datetime.datetime.now ()) # Get the current time, in particular to the second, return is datetime.datetime format . 7 Print (datetime.datetime.today ( )) # Get the current time to the second specific . 8 Print (date.today ()) # Get the current time, only to return date . 9 now = date.today () 10 Print (now.strftime ( ' %% Y-M-% M-H-%%% D- S ' )) # format display time . 11 Print(datetime.datetime.strptime ( ' 21/11/19 22:11 ' , ' % D /% m /% Y% H:% M ' )) # format display time 12 is Print (datetime.datetime.now () -datetime.timedelta (Days = 11)) # time of day 11 days ahead