How to use time Module in Python
This article mainly shows you "how to use the time module in Python", the content is easy to understand, clear, hope to help you solve your doubts, let the editor lead you to study and learn "how to use the time module in Python" this article.
1. Timestamp time.time the current time.
2. The time.sleep program pauses for three seconds.
3. Time.ctime current time.
Year, month, day, hour, minute, second.
4. Time.localtime () converts the timestamp into a tuple.
Displays details of the current time.
Time.mktime converts time tuples to timestamps.
Time.strftime () # converts the tuple time to a string.
Time.strptime () # converts strings to tuples.
Example
Import timet1 = time.time () print (T1) # the execution time of the program so far # time.sleep (3) # the program pauses for 3 seconds T2 = time.time () print (T2) s = time.ctime (T1) # current time print (s) # converts the timestamp into tuple form (current time details are displayed) loc = time.localtime (T1) print (loc) print (loc.tm_hour) # adjustable Use print (loc.tm_mon) # to convert the tuple into a timestamp loc = time.mktime (loc) print (loc) # clear zero after the decimal point # convert the tuple time into a string form s = time.strftime ('% Ymura% mmura% d') print (s) # print s = time.strftime ('% Y-%m-%d% HRV%) in the form of year, month and day MRV% S') print (s) # the way to convert a string into a tuple t = time.strptime ('2021 prime 9) 13' '% Y _ The second parameter is the format to be converted print (t) above is all the content of the article "how to use the time module in Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!