Tag: port specifies clock full index format identifying Dex timestamp
#Time ModuleImport Time#Common Methods#time.sleep (secs) # (thread) Delays the specified time run. Unit is Seconds#print (Time.time ()) #获取当前时间戳#three ways to represent time#in Python, there are typically three ways to represent time: timestamp, tuple (structured time), formatted time string:#1. Timestamp (timestamp): Typically, a timestamp represents an offset that is calculated in seconds from 00:00:00 January 1, 1970, and is a float type#2. Formatted time string (format string): ' 1972-1-2 '#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 system hours (0-23)#%I 12-hour hours (01-12)#%M minutes (00=59)#%s seconds (00-59)#%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#percent% of the number itself#3. Tuple (Struct_time): Struct_time A total of 9 elements (year, month, day, make, minute, second, week of the year, the day of the year, whether it is daylight saving time)#Index (Index) property (Attribute) value (values)#0 Tm_year (years) such as#1 Tm_mon (month) 1-12#2 Tm_mday (Sun) 1-31#3 Tm_hour (hours) 0-23#4 tm_min (min) 0-59#5 tm_sec (sec) 0-60#6 Tm_wday (weekday) 0-6 (0 = Monday)#7 Tm_yday (Day ordinal of the year) 1-366#8 tm_isdst (Daylight saving time) defaults to 0#time StampPrint(time.time)#Time StringPrint(Time.strftime ('%y-%m-%d'))Print(Time.strftime ('%y-%m-%d%h:%m:%s'))#Time tuple: localtime () converts a timestamp to the struct_time of the current time zonePrint(Time.localtime ())#Results:#2018-08-08#2018-08-08 16:13:36#time.struct_time (tm_year=2018, tm_mon=8, Tm_mday=8, tm_hour=16, tm_min=13, tm_sec=36, tm_wday=2, tm_yday=220, tm_ isdst=0)#Note: Timestamps are the time that a computer can recognize; a time string is a time that a person can understand; tuples are used to manipulate time .#conversions between several formats#1. Timestamp--Structured time#time.gmtime (timestamp) #UTC时间, consistent with local time in London, UK#time.localtime (timestamp) #当地时间. We are Beijing Yes gold, 8 hours difference from UTC timePrint(Time.gmtime (12000000000))#Results:#time.struct_time (tm_year=2350, tm_mon=4, tm_mday=7, tm_hour=21, tm_min=20, tm_sec=0, tm_wday=4, tm_yday=97, tm_ isdst=0)Print(Time.localtime (12000000000))#Results:#time.struct_time (tm_year=2350, tm_mon=4, Tm_mday=8, tm_hour=5, tm_min=20, tm_sec=0, tm_wday=5, tm_yday=98, tm_ isdst=0)#2. Structured time---> timestamp#Time.mktime (structured time)Time_tuple= Time.localtime (12000000000)Print(Time.mktime (time_tuple))#Results:#12000000000.0#3. Structure time---> string time#time.strftime (' format definition ', ' structured time ') if the structured time parameter is not passed, the current time is implementedPrint(Time.strftime ('%y-%m-%d'))Print(Time.strftime ('%y-%m-%d'), Time.localtime (12000000000))#Results:#2018-08-08#2018-08-08 time.struct_time (tm_year=2350, tm_mon=4, Tm_mday=8, tm_hour=5, tm_min=20, tm_sec=0, tm_wday=5, tm_yday= 98, tm_isdst=0)#4. String Time---> Structured time#time.strptime (' Time string ', ' string corresponding to format ')Print(Time.strptime ('2020-1-1','%y-%m-%d'))Print(Time.strptime ('2020/1/2','%y/%m/%d'))#Results:#time.struct_time (tm_year=2020, Tm_mon=1, Tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, Tm_yday=1, TM_ISDST =-1)#time.struct_time (tm_year=2020, Tm_mon=1, tm_mday=2, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=2, tm_isdst= -1)#5. Structured time--->%a%b%d%h:%m:%y string#Time.asctime (structured time) if the parameter is not passed, the format string of the current time is returned directlyPrint(Time.asctime ())Print(Time.asctime (Time.localtime (12000000000)))#Results:#Wed 8 16:42:30 2018#Sat APR 8 05:20:00 2350#6. Timestamp--->%a%b%d%h:%m:%y string#Time.ctime (timestamp) If the parameter is not passed, the format string of the current time is returned directlyPrint(Time.ctime ())Print(Time.ctime (12000000000))#Results:#Wed 8 16:44:31 2018#Sat APR 8 05:20:00 2350#Other methodsPrint(Time.clock ())#Calculate CPU Execution Time
Time of the Python module