Time module is primarily processed in Python
1.time.localtime ()
TM Year
TM Mon Month 1-12
TM Mday Date 1-31
TM Hour Hours 0-23
TM min Min 0-61
TM sec Sec. 0-61
TM Wday 0-6 weeks
TM yday number of days in the year 1-366
TM Isdst is daylight saving time, default is-1
>>> import time>>> time.localtime () time.struct_time (tm_year=2014, tm_mon=10, tm_mday=31, tm_hour= tm_min=10, tm_sec=45, tm_wday=4, tm_yday=304, tm_isdst=0)
2.time.time ()
Time.time returns the timestamp of the current time
Time stamp refers to the number of seconds from 1970-1-1 00:00:00 to the current experience
>>> time.time () 1414732515.903
3.time.mktime ()
Convert a struct time to a timestamp
>>> time.time () 1414732715.009>>> time.mktime (Time.localtime ()) 1414732723.0
4.time.sleep (secs)
A thread defers a specified time run, in seconds
5.time.gmtime (secs)
Time.gmtime (secs) similar to Time.localtime, when time.gmtime (secs) converts time to UTC time zone
>>> Time.gmtime (Time.struct_time) (tm_year=2014, tm_mon=10, tm_mday=31, tm_hour=5, tm_min=21, tm_sec=30, tm_ Wday=4, tm_yday=304, tm_isdst=0) >>> Time.gmtime (Time.time ()) Time.struct_time (tm_year=2014, tm_mon=10, tm_ Mday=31, Tm_hour=5, tm_min=21, tm_sec=54, tm_wday=4, tm_yday=304, tm_isdst=0) >>> time.localtime () time.struct _time (tm_year=2014, tm_mon=10, tm_mday=31, tm_hour=13, tm_min=22, tm_sec=6, tm_wday=4, tm_yday=304, tm_isdst=0)
6.time.clock ()
Different systems have different meanings. On a UNIX system, it returns \ process time, which is a floating-point number (timestamp) in seconds; In Windows, the first call returns the actual time that the process is running. And the second call is the run time from the first call to the present.
Import Timetime.sleep (3) Print time.clock () time.sleep (5) Print time.clock () time.sleep (8) Print time.clock ()
Execution results are
2.23109304818e-065.0150924520313.027484389
7.time.asctime ([t])
Time.asctime ([t]): A tuple representing time expressed as a struct
If there are no arguments, the time.localtime () will be passed in as a parameter
8.time.ctime ([secs])
Time.ctime ([secs]): Converts a timestamp (floating point number in seconds) to the form of Time.asctime ().
If the parameter is not given or is none, the default Time.time () is the parameter. Its function is equivalent to Time.asctime (Time.localtime ())
>>> time.asctime () ' Fri Oct to 13:33:41 ' >>> time.asctime ((3, 8, 5, 1, 1)) ' Sat Mar 14:08:23 ' >>> time.ctime (1211111111.111) ' Sun may 19:45:11 ' >>> time.ctime () ' Fri Oct 31 13 : 39:53 2014 '
9.time.strftime (format[, T])
Converts the specified struct time (default) to the specified format string output
Python format symbols in time date
%y Two-digit year representation (00-99)
%Y Four-digit year representation (000-9999)
%m Month (01-12)
One day in%d months (0-31)
%H 24-hour hours (0-23)
%I 12-hour hours (01-12)
%M minutes (00-59)
%s seconds (00-59)
>>> time.strftime ('%y%m%d%h%m%s ', Time.gmtime ()) ' 20141031054206 ' >>> time.strftime ('%y%m%d%h%m%s ' 20141031134213 ' >>> time.strftime ('%y-%m-%d%h:%m:%s ') ' 2014-10-31 13:43:19 '
Python format symbols in time date
%a Local Simplified Week name
%A Local Full week name
%b a locally simplified month name
%B Local Full month name
%c Local corresponding date representation and time representation
%j Day of the Year (001-366)
%p the equivalent of a local a.m. or p.m.
%u weeks of the year (00-53) Sunday is the beginning of the week
%w Week (0-6), Sunday for the beginning of the week
%W Week of the Year (00-53) Monday is the beginning of the week
%x Local corresponding date representation
%x Local corresponding time representation
%Z the name of the current time zone
The percent number itself
This article is from the "Raffaele" blog, make sure to keep this source http://raffaele.blog.51cto.com/6508076/1570328
Python Learning notes 7-time module