1, where the format_string type of time and struct_time between can be converted, timestamp time stamp can be converted between struct_time, but time stamp and format time is not directly converted.
The functions that the time module contains include the ability to get current times, operation times and dates, read time from strings, and format time as strings.
Timestamp timestamp, which represents the offset that is calculated in seconds from 00:00:00 on January 1, 1970;
A function that returns a timestamp consists of a time (), clock (), and other struct_time, a total of nine element groups. Gmtime (), localtime (), strptime () format time, the formatted structure makes time more readable.
Includes custom formats and fixed formats
2. Two ways to get the current date
= Time.strftime ("%y-%m-%d"= Datetime.datetime.now (). Strftime ("% y-%m-%d") print (now_date)
3. Get the time before or after the current time
Import Datetimeimport time# Gets the current hour, the day before, the week before, the first one months Now_date=Datetime.datetime.now () print (Now_date.strftime ("%y-%m-%d%h:%s:%m") # 1 hours ago D1= Now_date-datetime.timedelta (hours=1) Print (D1.strftime ("%y-%m-%d%h:%s:%m"))# 1Days ago (1 days later +) D2= Now_date-datetime.timedelta (days=1) Print (D2.strftime ("%y-%m-%d%h:%s:%m"))
4. Calculate Program Run time
= time.time () time.sleep (2=-start_time)
5. Time string converted to timestamp, string converted to time
# string time-to-time rub datestr1 = " 2015-06-06 10:10:10 " Print (Time.strptime (datestr1, " %y-%m-%d %h:%m:%s " " %y-%m-%d%h:%m: %s -struct_ Time (localtime)-strtime (strftime)) time1 = Time.time () print (time1) print (Time.localtime (time1)) print (Time.strftime ( " %
6, Time.clock () function Introduction at the time of the first call, the actual time of the program running is returned;
After the second call, the time interval from the first call to the call is returned
Under the Win32 system, this function returns the real time (wall times), while the CPU time is returned under Unix/linux.
References: 79044905
Python Time module Introduction and application