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

Example Analysis of python time and date Module

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail the example analysis of the python time and date module. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. The time module is implemented by calling the C library, so some methods may not be called on some platforms.

But most of the interfaces they provide are basically the same as the C standard library time.h.

2. The interface provided by datetime module is more intuitive, easier to use and more powerful.

3. Calendar module is suitable for date, especially in the form of calendar.

Example

Import timeimport calendar # timestamp timestamp = time.time () print (timestamp) # returns a readable form of Mon Aug 30 23:00:35 2021 "; ctime (args) asctime (args), args can not be passed, or you can pass the time tuple struct_timec_time = time.ctime () print (c_time) asc_time = time.asctime () print (asc_time) # return the time tuple struct_time at local time Localtime (args), args may not be passed You can also pass floating point localtime = time.localtime () print (localtime) # output: time.struct_time (tm_year=2021, tm_mon=8, tm_mday=30, tm_hour=23, tm_min=14, tm_sec=55, tm_wday=0, tm_yday=242 Tm_isdst=0) # time tuple split year = localtime.tm_year # month = localtime.tm_mon March y_day = localtime.tm_yday # Day of year m_day = localtime.tm_mday # Day of January w_day = localtime.tm_wday # Day of week hour = localtime.tm_hour # when minute = localtime.tm_min # split sec = localtime .tm _ sec # seconds isdst = localtime.tm_isdst # is daylight saving time Values are: 1 (daylight saving time), 0 (not daylight saving time),-1 (unknown) Default-1 # format time to string # 24-hour display format_time = time.strftime ('% Y-%m-%d% HV% MV% Swatch, localtime) print (format_time) # output 2021-08-30 23V 21V 5h 12-hour display f_time = time.strftime ('% Y-%m-%d% I% MVA% S' Localtime) print (f_time) # output 2021-08-30 11lv 23ghuo string transfer time return time tuple p_time = time.strptime (format_time,'% Y-%m-%d% H15% Mpura% S') print (p_time) # Calendar cal = calendar.month (2021) 8) print (cal)''output result: August 2021Mo Tu We Th Fr Sa Su 12 3 4 5 6 7 8 9 10 11 12 13 14 1516 17 18 2021 2223 24 25 26 27 28 2930 31' 'this is the end of the article on "sample Analysis of python time and date Module" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

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