Time module:
1 Import Time2 3 #get timestamp, from 1970 to 1.1 hours to now time, 1970 appear Unix4 Print(Time.time ())5 6 #returns the string pattern of time, which defaults to the current system time7 Print(Time.ctime ())8 Print(Time.ctime (Time.time ()-86400))#number of seconds in 864,001 days9 Ten #return Struct_time object, East eight time, 8 hours earlier than China OneTM =time.gmtime () A Print(tm) - Print(tm.tm_hour,tm.tm_min) - the #returns the Struct_time object for local time - Print(Time.localtime ()) - - #convert a struct object to a timestamp + Print(Time.mktime (Time.gmtime ())) - + #Time delay, in seconds ATime.sleep (5) at Print("%%%%") - - #Convert a Struct_time object to a string format -TM1 = Time.strftime ("%y-%m-%d%h:%m:%s", Time.gmtime ()) - Print(TM1) - Print(Type (TM1)) in - #Convert a string format to a struct object toTM2 = Time.strptime ("2016-05-6 15:06","%y-%m-%d%h:%m") + Print(TM2) - the #convert a struct object to a timestamp * Print(Time.mktime (TM2))
DateTime module:
Import TimeImportdatetime#date format can be directly judged#Output Current date 2017-02-06Print(Datetime.date.today ())#convert timestamps to date formatsPrint(Datetime.date.fromtimestamp (Time.time ()))#output current time, accurate to millisecondsPrint(Datetime.datetime.today ())#convert current time to struct_time formatCurrent_time =Datetime.datetime.today ()Print(Current_time.timetuple ())#Replacement TimePrint(Current_time.replace (1993,7,8,10))#The addition and subtraction of time, Days.seconds.microseconds,milliseconds,minutes,hours,weeksPrint(Datetime.datetime.now () + Datetime.timedelta (days=10))Print(Datetime.datetime.now ()-Datetime.timedelta (days=10))
Python Learning Path-time module