#-*-coding=utf-8-*-__author__='Piay'Import Timedefget_struct_time ():" "You can use list or string formatting tm_year--> tm_mon--> month tm_mday--> day tm_hour--> tm_min--> minutes Tm_sec--> sec tm_wday--> 0-6 (0 for Week 1) tm_yday--> Day of the Year (1-366) tm_isdst--> is daylight saving time, default is -1:return:--& Gt;time.struct_time (tm_year=2016, tm_mon=6, tm_mday=16, tm_hour=23, tm_min=29, tm_sec=13, tm_wday=3, tm_yday=168, tm_i sdst=0)" " returntime.localtime ()#Time.localtime ([sec]) converts a timestamp to the current time zone's struct) if the _time,sec parameter is not provided, the currentPrinttime.localtime ()#----->time.struct_time (tm_year=2016, tm_mon=6, tm_mday=19, tm_hour=12, tm_min=57, tm_sec=17, tm_wday=6, tm_ yday=171, tm_isdst=0)#Time.gtime ([sec]) is similar to localtime only when converted to UTC time zonePrinttime.gmtime ()#----->time.struct_time (tm_year=2016, tm_mon=6, tm_mday=19, tm_hour=4, tm_min=57, tm_sec=17, tm_wday=6, Tm_yday =171, tm_isdst=0)#returns the timestamp of the current timePrinttime.time ()#----->1466312237.8#time.mktime convert Struct_time to timestampPrintTime.mktime (Time.localtime ())#----->1466312237.0#converts a struct_time (the default is the current time) to a stringPrinttime.asctime ()#---->sun June 12:57:17#The Time.clock () function has two functions: the first call returns the actual time the program is running, the first call after the call, the return is from the first call, after the#the time interval for this callTime.sleep (1)Print 'clock1:%s'%Time.clock () time.sleep (1)Print 'clock2:%s'%Time.clock () time.sleep (1)Print 'clock3:%s'%Time.clock ()#output: clock1:2.93333370582e-06---> Output program run time#clock2:1.00065301596 The time interval between the output and the first clock#clock3:2.00075212073 The time interval between the output and the first clock#thread decline time run, parameter unit is seconds, for example sleep1 seconds#sleep time is not very accurate, there is a floating value, the parameter can be a floating point number, can be guaranteed accurate to 0.1sTime.sleep (1.5)#time.strftime ()" "strftime (format[, tuple]), string will specify the Struct_time (default current time), output python in the time date format symbol according to the specified format string:%y A two-digit year representation (00-99)%Y a four-digit year represents (000-9999) the day of the%m month (01-12)%d months (0-31)%H 24-hour 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 locally simplified month name%b Local full month name%c local corresponding date representation and time representation%j year The day of the Week (001-366)%p the equivalent of the local A.M. or p.m. number of weeks in the year (00-53) Sunday for the beginning of the week%w Week (0-6), Sunday for the beginning of the week%w the week of the Year (00-53) Monday for the beginning of the week%x local corresponding day The period indicates that%x local corresponding time represents the name of the current time zone%Z%% itself" "PrintTime.strftime ('%y-%m-%d%h:%m:%s', Time.localtime ())#--->2016-06-19 14:26:18#time.strptime ()" "strptime (string, format), Struct_time converts a time string to an array of time based on the specified format character" "PrintTime.strptime ('9 10:22:32','%Y%m%d%h:%m:%s')#-->time.struct_time (tm_year=2016, tm_mon=9, tm_mday=25, tm_hour=10, tm_min=22, tm_sec=32, tm_wday=6, tm_yday= 269, Tm_isdst=-1)
Python Time module functions