In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to find out Python time and date problems, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this to learn, I hope you can gain something.
Python programs have many built-in modules that handle the way dates and times are handled, such as calendar, time, datetime. calendar is used to deal with calendar correlation;time provides an interface that is basically the same as the C standard library time.h, while the datetime module interface is more intuitive and easier to call.
Today, Xiao U mainly shares with you the time module and calendar module ~
Before we talk about these two modules, let's first understand what a time tuple is. Many Python functions process time with nine sets of numbers assembled from a single element.
serial number
field/property
value
4 digit year tm_year
2008
1
Month tm_mon
1 to 12
3
TM_mday
1 to 31
4
hour tm_hour
0 to 23
5
minutes tm_min
0 to 59
6
seconds tm_sec
0 to 60
7
Day of the week tm_wday
1 to 7
8
Day of the year
tm_yday
1 to 366
9
Summer Time tm_isdst
-1, 0, 1, -1 is the flag that decides if it's daylight saving time.
time How to get the current time
To convert from a timestamp way of returning a floating point number to a time tuple, simply pass the floating point number to a function such as localtime. Specific examples:
#!/ usr/bin/python
# -*- coding: UTF-8 -*-
import time localtime = time.
localtime(time.time())
print "Local time is:", localtime
Output:
Local time is: time.struct_time(tm_year=2018, tm_mon=11, tm_day =28, tm_hour=18, tm_min=30, tm_sec=47, tm_wday=3, tm_day =333, tm_isdst=0)
Calendar How to get a calendar for a month
Calendar modules are calendar related, such as printing a month's character calendar. Monday is the default first day of the week and Sunday is the default last day. Let's look at specific examples:
#!/ usr/bin/python
# -*- coding: UTF-8 -*-
import calendar
cal = calendar.month(2018, 12)
print "Output the calendar for December 2018 as follows:"
print cal
Output:
The following output calendar for December 2018:
December 2018
Mo Tu We Th Fr Sa Su
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
The above are two examples that Xiao U shared for everyone in a few days. If there is any problem that you don't understand, you can throw the problem over ~
Finally, I sorted out a [python time date formatting symbol] for everyone. There is a collection that needs it ~
%y Two-digit year representation (00-99)
%Y four-digit year representation (000-9999)
%m Month (01-12)
%d Day of month (0-31)
%H 24 hours (0-23)
%I 12 hours (01-12)
%M minutes (00=59)
%S seconds (00-59)
%a Local Simplified Week Name
%A Local full week name
%b local simplified month name
%B Local full month name
%c Local corresponding date and time representations
%j Day of the year (001-366)
%p Equivalent of local A.M. or P.M.
%U Number of weeks in the year (00-53) Sunday is the beginning of the week
%w Week (0-6), Sunday is the beginning of the week
%W Number of weeks in the year (00-53) Monday is the beginning of the week
%x local corresponding date representation
%X Local corresponding time representation
%Z Name of current time zone
%% % itself.
Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.
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.