Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use time Module in Python

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report