In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge of this article "python how to get the date of the current system" is not quite understood by most people, so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to get the date of the current system by python" article.
Get the date of the current system
Python acquires the current system time, mainly through the datetime module in Python.
Import datetimefrom time import strftime
Get the current time
Now=datetime.datetime.now () print (now.strftime ("Y-%m-%d H:%M:%S"))
Get the time after the current time + 3 minutes:
UpperTime= (datetime.datetime.now () + datetime.timedelta (minutes=3)) .strftime ("% Y-%m-%d% H:%M:%S") print (upperTime)
Get the time after the current time + 5 minutes:
UpperTime= (datetime.datetime.now () + datetime.timedelta (minutes=5)) .strftime ("% Y-%m-%d% H:%M:%S") print (upperTime)
The printed results are as follows:
2022-04-16 07:47:54
2022-04-16 07:50:54
2022-04-16 07:52:54
Timedelta- interval, that is, the length between two time points
Now (tz=None) returns the current local date and time. If the optional parameter tz is not specified, it is the same as today ().
Strftime (format) returns a string that represents a date, controlled by an explicitly formatted string. Format codes that reference hours, minutes, or seconds will see a value of 0.
The datetime package gets the current date and time
A method to get the current date and time in python using the datetime package.
Datetime class
Datetime is a component package built into python, with a datetime class in the datetime package and a now () method to get the datetime object of the current time:
Import datetimenow = datetime.datetime.now () print (now) # 2022-03-20 18purl 32purl 14.178030
The datetime class has year, month, day, hour, minute, second, microsecond and other members, such as the object now above:
# now: datetime.datetime (2022, 3, 20, 18, 32, 14, 178030) print (now.year) # 2022print (now.month) # 3print (now.day) # 20strftime outputs characters in the specified format
The method strftime of the datetime class returns a string from the datetime object in the specified format (without changing the object itself):
S = now.strftime ('% y% m% d') print (s) # '220320'print (now) # 2022-03-20 18VlV 3215 14.17803 now: datetime.datetime (2022, 3, 20, 18, 32, 14, 178030)
Among them, the commonly used format is as follows:
Year representation of% y double digits (00-99)
The year of% Y four digits is expressed (000-9999)
% m month (01-12)
One day in% d months (0-31)
% H 24 hours (0-23)
% M minutes (00-59)
% s seconds (00-59)
The above is about the content of this article on "how to get the date of the current system by python". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.