Import time Use the most frequent module 1, get the current time (1) timestamp time.time () Timestamp: from January 1, 1970 0 o'clock to now offset by seconds (2) Time tuple time.localtime () The returned time tuple, 9 values Time.struct_time (tm_year=2017, tm_mon=5, tm_mday=28, tm_hour=9, tm_min=43, Tm_sec=3, Tm_wday=6 (Day of the week) , tm_yday=148 (the Day of the year), tm_isdst=0 (whether daylight saving time)) A, the value in the calling tuple T1=time.localtime () print t1.tm_year,t1.tm_hour often use this method of invocation, Compare visual print t1[0],t1[2] 2, timestamps, and time-tuple conversions (1) timestamp to time primitive t2=time.time () time.sleep () time.localtime (T2) Convert the timestamp obtained from 10 seconds to a time Ganso (2) converts the time element ancestor to timestamp mktime () time.mktime (T3) 3, time application (1) Format output time.strftime () format time: Convert time tuple to format time T4 =time.localtime () Print time.strftime ('%y-%m-%d%h:%m:%s ', T4) specify time T4 formatted output print time.strftime ('%y-%m-%d%h:%m:%s ') Formatted output of the current time%y (years)-%m (month)-%d (day)%H (hours):%m (min):%s (SEC) 2, other formatted parameter%c local string representation of corresponding date and time (e.g. 15/08/27 10:20:06)%x local corresponding date string (for example, 15/ 08/01)%x Local corresponding time string (such as 08:08:10)%w the day of the one week (0-6,0 is Sunday)%a Local week name shorthand (e.g. Thursday for Thu)%a the full name of local week names (e.g. Thursday for Thursday)%b Shorthand for local month names (such as August Agu)%B The full name of the local month names (for example, August is August)%j the day of the Year (001-366)%u in the week of the year. (00-53 weeks is the beginning of one weeks.) All days before the first Sunday are placed on the No. 0Week. (2) Statistical interface call time, program execution elapsed time Starttime=time.time () interface or running program Endtime=time.time () spendtime=endtime-starttime Unit is seconds (difference in timestamp) (3) The formatted time is converted to a time tuple strptime () is the inverse operation of the time.strftime () function strtime= ' 2015-12-21 09:54:23 ' formattime= Time.strptime (Strtime, '%y-%m-%d%h-%m-%s ') '%y-%m-%d%h-%m-%s ' This format needs to match the format strtime in 4, get Greenwich Mean (UTC+0) Time.gmtime () T3=time.gmtime () returns the time tuple 5, wait method (1) Time.sleep () (2) Time.clock () The number of seconds the function calculates in floating-point numbers returns the current CPU time on different systems with different meanings. On the NUIX system, it returns "process time", which is a floating-point number (timestamp) in seconds. In Windows, the first call returns the actual time at which the process was run. And the second call is the run time from the first call to the present.
Python Date: Time module