Time
Transfer from http://www.cnblogs.com/zhaof/p/5809246.html
Http://www.runoob.com/python/python-date-time.html
#Coding=utf-8Import Time#number of milliseconds from 1970Print("Time.time", Time.time ())#To convert a timestamp to the current time tuplePrint("Time.localtime", Time.localtime ())#converts a timestamp into a tuple of the current time UTC timePrint("Time.gmtime", Time.gmtime ())#time.mktime () can convert struct_time to timestampx =time.localtime ()Print("Time.mktime", Time.mktime (x))#Time.strftime replacing struct_time with a formatted time stringPrint("Time.strftime", Time.strftime ("%y-%m-%d%h:%m:%s", x))#Time.strptime can convert a formatted time string to Struct_timePrint("Time.strptime", Time.strptime ("2016-08-24 14:05:32","%y-%m-%d%h:%m:%s"))#time.asctime Convert Struct_time to wed 24 14:22:47 2016 this formatPrint("Time.asctime", Time.asctime (x))#Replace the time stamp with the number of seconds wed 14:22:47x =time.time ()Print(x)Print("Time.ctime", Time.ctime (x))
Print ("Datetime.datetime.now", Datetime.datetime.now ())
Run results
D:\Python\Python35\python.exe d:/pycharmprojects/pythonoo/TimeTest.pytime.time1491921917.7223847time.localtime time.struct_time (tm_year=2017, tm_mon=4, tm_mday=11, tm_hour=22, tm_min=45, tm_sec=17, Tm_wday=1, tm_yday=101, tm_isdst=0) time.gmtime time.struct_time (Tm_year=2017, tm_mon=4, tm_mday=11, tm_hour=14, tm_min=45, tm_sec=17, Tm_wday=1, tm_yday=101, tm_isdst=0) Time.mktime1491921917.0Time.strftime2017-04-11 22:45:17time.strptime time.struct_time (tm_year=2016, Tm_mon=8, tm_mday=24, tm_hour=14, tm_min=5, tm_sec=32, tm_wday=2, tm_yday=237, Tm_isdst=-1) time.asctime Tue Apr11 22:45:17 20171491921917.7354486time.ctime Tue APR11 22:45:17 2017Datetime.datetime.now2017-04-11 22:45:17.735448ProcessFinished with exit code 0
Formatting
%a local (locale) simplifies week name%A Local Full week name%b Local simplified month name%B Local Full month name%c Local corresponding date and time representation%d the day of the one month (01-31)%H hours of the day (24-hour, 00-23)%I Number of hours (12-hour system, 01-12)%j Day of the Year (001-366)%m Month (01-12)%M minutes (00-59)%p Local am or PM's corresponding character%s seconds (01-61)%u the number of weeks in a year. (00-53 Weeks is the beginning of one weeks. All days before the first Sunday are placed in the No. 0 week. %w the day of the one week (0-6, 0 is Sunday)%W and%u are basically the same, the difference is%W takes Monday as the beginning of one weeks. %x Local corresponding date%X Local corresponding time%y the year of the century was removed (00-99)%Y Full Year%the name of the Z time zone (if it does not exist as a null character)Percent '% ' character
"Python" time