One or three methods of representation
1. Timestamp (timestamp):
Time.time () #得到的是float类型
2. Formatting (format String):
Time.strftime ('%y/%m/%d%h:%m:%s ') #得到的是字符串类型
3. Structured (struct_time):
Time.localtime ()
#Import Time Module>>>Import Time#time Stamp>>>time.time ()1500875844.800804#Time String>>>time.strftime ("%y-%m-%d%x")'2017-07-24 13:54:37'>>>time.strftime ("%y-%m-%d%h-%m-%s")'2017-07-24 13-55-04'#time tuple: localtime converts a timestamp to the struct_time of the current time zonetime.localtime () time.struct_time (Tm_year=2017, tm_mon=7, tm_mday=24, Tm_hour=13, tm_min=59, tm_sec=37, Tm_wday=0, tm_yday=205, tm_isdst=0)
Summary: Time stamp is the time that the computer can recognize; The time string is the time that a person can read; Tuples are used to manipulate time.
Ii. conversions between several formats
#Timestamp-- structured time#time.gmtime (timestamp) #UTC时间, consistent with local time in London, UK#time.localtime (timestamp) #当地时间. For example, we are now implementing this method in Beijing: 8 hour difference from UTC time, UTC time + 8 hour = Beijing Time>>>time.gmtime (1500000000) time.struct_time (tm_year=2017, Tm_mon=7, tm_mday=14, tm_hour=2, tm_min=40, tm_sec=0, tm_wday=4, tm_yday=195, tm_isdst=0)>>>time.localtime (1500000000) time.struct_time (tm_year=2017, Tm_mon=7, tm_mday=14, tm_hour=10, tm_min=40, tm_sec=0, tm_wday=4, tm_yday=195, tm_isdst=0)#structured time-time stamping#Time.mktime (structured time)>>>time_tuple = Time.localtime (1500000000)>>>time.mktime (time_tuple)1500000000.0
View Code
#structured Time--string time#time.strftime ("format definition", "structured Time") if the structured time parameter does not pass, the actual current time>>>time.strftime ("%y-%m-%d%x")'2017-07-24 14:55:36'>>>time.strftime ("%y-%m-%d", Time.localtime (1500000000))'2017-07-14'#string Time--structured time#Time.strptime (Time string, string corresponding format)>>>time.strptime ("2017-03-16","%y-%m-%d") time.struct_time (tm_year=2017, Tm_mon=3, tm_mday=16, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=75, Tm_isdst=-1)>>>time.strptime ("07/24/2017","%m/%d/%y") time.struct_time (tm_year=2017, Tm_mon=7, tm_mday=24, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=205, Tm_isdst=-1)View Code
#structured Time--%a%b%d%h:%m:%s%y string#Time.asctime (structured time) if the parameter is not passed, the format string of the current time is returned directly>>>time.asctime (Time.localtime (1500000000))'Fri Jul 10:40:00'>>>time.asctime ()'Mon Jul 15:18:33'#%a%d%d%h:%m:%s%y string--structured time#Time.ctime (timestamp) If the parameter is not passed, the format string of the current time is returned directly>>>time.ctime ()'Mon Jul 15:19:07'>>>time.ctime (1500000000)'Fri Jul 10:40:00'
View Code
Python-day21--time Module