I. Definite time tuple
Second, the test code
1493368879.41, timestamp print time.time () # Gets a tuple, time.struct_time (tm_year=2017, tm_mon=4, tm_mday=28,# tm_hour=16, tm_ min=41, tm_sec=19, tm_wday=4, tm_yday=118, tm_isdst=0) print time.localtime () print time.localtime (Time.time ()) #格式化时间 # Fri Apr 16:31:38 2017print time.asctime (Time.localtime (Time.time ())) # time format conversion, parameters (format, tuple) print time.strftime ("%y-%m-% D%h:%m:%s ", Time.localtime ()) Print time.strftime ("%y/%m/%d%h/%m/%s ", Time.localtime ()) Print time.strftime ("%Y--% m--%d%h--%m--%s ", Time.localtime ()) Print time.strftime ("%Y%M%d%h--%m--%s ", Time.localtime ()) # formatted as Sat 28 22:24:24 2016 form print time.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ()) # string Conversion Narimoto Group Strtime = "2017/08/23" #元组类型print Time.strptime (Strtime, "%y/%m/%d") # tuple converted to timestamp print time.mktime (Time.strptime (Strtime, "%y/%m/%d") #---------------- ------------------------------------------------------------------------------
third, Python in time date formatting symbols:
- %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)
- %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 this
Iv. testing the results of the code
Python Time Module Introduction