In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the Python time operation time how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
1. Overview of time
The computer network time began at 0: 00 on January 1, 1970, the first year of UNIX.
The Python time module mainly accesses and converts time.
There are three forms of time:
Timestamp (timestamp): a floating-point number that can be added or subtracted
Format time string (string_time): represents a common time format example 2021-10-29
Structured time (struct_time): a multivariate tuple of the year, month, day, hour, and second.
Important note:
The Python time module currently supports only 2038.
UTC (Universal coordinated time), also known as Greenwich mean time, Universal Standard time
DST Daylight time. Speed up by one hour at a certain time according to local time
Python time is an immutable type and cannot be changed by read only
two。 Format time string meaning% an abbreviation of local week name (e.g. Thursday is Thu)% A full name of local week name (e.g. Thursday is Thursday)% b abbreviation of local month name (e.g. August is agu)% B full name of local month (such as August is august)% c string representation of local corresponding date and time (e.g. 1508) / 27 10:20:06) d number of the month (01-31)% f microseconds (range 0.999999)% H hours of the day (24-hour system) 00-23)% I hours (12 hours, 0-11% j days of the year (001-366)% m months (01-12)% M minutes (00-59)% p Local am or pm identifier% S seconds% U week of the year. Sunday is the beginning of the week. )% w the day of the week (0-6) 0 is Sunday)% W days of the year (1-54)% x local corresponding date string (e.g. 15-08-01)% X local corresponding time string (e.g. 08:08:10)% y minus century year (00-99) year Y complete year (4 digits represent year such as 2021) interval between z and UTC time (if it is local time Return empty string) name of% Z time zone (if it is local time, empty string)%'% 'character 3. Time structured index property value range 0tm_year (year) for example, 20211tm_mon (month) 1~122tm_mday (day) 1~313tm_hour (hour) 0~234tm_min (minute) 0~595tm_sec (second) 0cm 61 (60 or 61 is leap second) 6tm_wday (weekday) 0~67tm_yday (day of the year) 1~3668tm_isdst (is daylight saving time)-14. Time related methods function time.sleep (t) sleep t seconds, t can be a floating point number or integer time.time () to obtain the current system timestamp time.gmtime (sec) timestamp converted into UTC structured time, sec default time.time () as a parameter time.localtime (sec) timestamp converted to the current structured time Sec default time.time () as parameter time.ctime (sec) timestamp converts to local time format string, sec default time.time () as parameter time.asctime (t) converts structured time into format string Time.localtime () as a parameter time.mktime (t) converts the structured time into a timestamp time.strftime (format, [t]) the local time that converts the structured time to the specified string format defaults to time.localtime () time.strptime (string, [t]), converts the formatting time to the structured time time.clock () returns the CPU time 5. Practice import time# to get the local timestamp stamp = time.time () # get the local gmt time gmt = time.gmtime () # get the local time local = time.localtime () # Local time format strtime = time.ctime () # the structured time is converted to the format character asctime = time.asctime () # convert the structured time to the timestamp constamp = time.mktime (local) # convert the structured time to the structured time Replace it with the specified string format time strf = time.strftime ("% Y-%m-%d% H:%M:%S") # convert the format time to structured time str = time.strptime ("2021-10-29 21:07:24" "% Y-%m-%d% H:%M:%S") print ("get local timestamp:", stamp) print ("get local gmt time:", gmt) print ("get local time:", local) print ("local time format:", strtime) print ("convert structured time to format characters:", asctime) print ("convert structured time to timestamp:" Constamp) print ("convert structured time to specified string format time:", strf) print ("convert formatting time to structured time:", str)
Thank you for reading this article carefully. I hope the article "how to use time in Python" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.