The time module is represented in three ways:
Timestamp (the timestamp is how many seconds have elapsed since January 1, 1970). )
Structured Time.
String Time.
One. Show Time stamp
Time.time (): Displays the timestamp of the current Time.
Print Time.time ()
>>>1490326825.62
TWO. Displays the current structured time.
Time.localtime (): Displays the structured time of the current time, and the time stamp can also be converted to a structured time type.
t = time.localtime ()
Let's take a look at what type of data time.localtime () Returns.
Print Type (t)
>>><type ' Time.struct_time ' >
This is a structured time object, then print it and see what's in it.
>>>time.struct_time (tm_year=2017, tm_mon=3, tm_mday=24, tm_hour=11, tm_min=45, tm_sec=20, tm_wday=4, tm_yday =83, tm_isdst=0)
Tm_year: the current year.
Tm_mon: the current Month.
Tm_mday: The current date is the Number.
Tm_hour: what time Is it now?
Tm_min: the current Minute.
Tm_sec: the current number of SECONDS.
Tm_wday: is currently the day of the week (Monday represents the No. 0 day of the week, starting from 0. )
Tm_yday: is currently the day of the Year.
Time.localtime () can pass in a timestamp format parameter and convert the timestamp to a structured time type.
Three. convert the timestamp to a formatted Time.
Time.localtime (1490326825.62)
Four. Convert the structured time to a timestamp.
Time.mktime () passes in a structured time object, transforming the structured time into a timestamp.
Five. Convert the string time to a formatted time Object.
Time.striptime (' time String ', format)
Print Time.strptime (' 2017-03-24 15:34:26 ', '%y-%m-%d%h:%m:%s ')
>>>time.struct_time (tm_year=2017, tm_mon=3, tm_mday=24, tm_hour=15, tm_min=34, tm_sec=26, tm_wday=4, tm_yday =83, Tm_isdst=-1)
SIX. converts a formatted time object into a string time format.
Time.strftime (' Format ', format time Object)
Print Time.strftime ('%y-%m-%d%h:%m:%s ', time.localtime ())
>>>2017-03-24 15:34:26
Seven. Display the string time directly.
Time.asctime () A string time is output when the default is not to add Parameters.
Asctime can pass a formatted time object and convert the formatted time object to a string format Output.
Eight. timestamp to String.
Time.ctime () will output a string time in the same way as asctime without the parameter being added by Default.
CTime can also pass in a timestamp to convert the timestamp to a string time.
Other:
Time.sleep () postpones a thread to run for a specified time in SECONDS.
This article is from the "rebirth" blog, make sure to keep this source http://suhaozhi.blog.51cto.com/7272298/1910077
6.python Time Module