#Time Calendar#Time Module#provides the ability to process time and convert between representations#gets the current time stamp#Concept#from 0 time zone January 1, 1970 0:0 0 seconds to the number of seconds of the given date time#floating point number#How to get#Import Time#time.time ()ImportTimeresult=time.time ()Print(Result)#get a time tuple#Concept#many Python time functions process the time as a 9-digit tuple#Illustrations##How to get#Import Time##time.localtime ([seconds])#seconds#Optional timestamp#Default Current timestamp#get the formatted time#second-to-read timeresult =time.localtime ()Print(Result)#time.struct_time (tm_year=2018, tm_mon=2, tm_mday=23, tm_hour=22, tm_min=50, tm_sec=35, tm_wday=4, tm_yday=54, tm_ isdst=0)#Import Time##time.ctime ([seconds])#seconds#Optional timestamp#Default Current timestamp#time Tuple--readable timeresult =time.ctime ()Print(Result)#Fri Feb 22:51:28 2018#Import Time##time.asctime ([p_tuple])#P_tuple#Optional time-tuple#default Current time tuple#Format Date string < timestamp#time Tuple-formatted dateresult =time.asctime ()Print(Result)#Fri Feb 22:52:18 2018#time.strftime (format string, time tuple)#For example#time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())#2017-0#9-02#17:21:00#formatting dates, time tuplesresult = Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())Print(Result)#2018-02-23 22:54:27#time.strptime (date string, format character string)#Time.mktime (Time tuple)#For example#Time.mktime (Time.strptime ("2017-09-02 17:21:00", "%y-%m-%d%h:%m:%s"))#1504344060.0#Common Format characters#% y#Two-digit year representation (00-99)#% Y#Four-digit year representation (000-9999)#% m#month (01-12)#% d#Day of the Month (0-31)#% H# -#hours of Hour (0-23)#% I# A#hours of Hour (01-12)#% M#Number of minutes (xx =)#% 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#Day of the Year (001-366)#% P#equivalent of local a.m. or P.M.#% U#Week 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#%% number itself#get current CPU time#Time.clock ()#number of seconds for floating-point numbers#can be used to count the execution time of a program codeStartime =Time.clock () forIinchRange (0,1000): Print(i) EndTime=Time.clock ()Print(EndTime-startime)#Sleep n seconds#delaying the execution of a thread can be easily understood as having the program pause#time.sleep (secs)#time.sleep (1)Print("......")#Calendar Module#provides calendar-related features, such as the ability to print a text calendar for a given month or year#get a calendar for a monthImportCalendarPrint(Calendar.month (2018, 2))#datetime Module#Python's standard library for working with dates and times#This module has a DateTime class, in addition to the date class, and the time class#You can do some calculations and things like that#get today's dateImportdatetimePrint(Datetime.datetime.now ())#2018-02-23 23:24:32.644703Print(Datetime.datetime.today ())#2018-02-23 23:24:32.644704#get the current month and day seconds separately#Some properties inside a DateTime object# Year#Month# Day#Hour#minute#Second#Calculate the date after n daysImportDatetimeresult= Datetime.datetime.today () + Datetime.timedelta (days = 7)Print(Result)#2018-03-02 23:24:32.644704#get two time difference between datesImportDatetimefirst= Datetime.datetime (2017, 9, 1, 12, 0, 0) second= Datetime.datetime (2017, 9, 2, 12, 0, 0) result= Second- FirstPrint(Result.total_seconds ())
Python Time Calendar Type