Python datetime.isoweekday()方法 (Python datetime.isoweekday() Method)
datetime.isoweekday() method is used to manipulate objects of datetime class of module datetime.
datetime.isoweekday()方法用于操作模块datetime的datetime类的对象。
It uses a datetime class object and returns the day of the week as an integer, where Monday is 1 and Sunday is 7. It is the same as datetime.weekday() function where we consider Monday is 0 incrementing by one for the coming days. It is an instance method as it works on an instance of the date class.
它使用datetime类对象并以整数形式返回星期几,其中Monday是1,Sunday是7。它与datetime.weekday()函数相同,在该函数中 ,我们认为星期一在接下来的几天中0递增1。 。 它是一个实例方法,因为它可用于date类的实例。
Module:
模块:
import datetime
Class:
类:
from datetime import datetime
Syntax:
句法:
isoweekday()
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is a number which tells us what is the day of the week on that day.
此方法的返回类型是一个数字,该数字告诉我们当天的星期几。
Example:
例:
## importing datetime class
from datetime import datetime
## Since we know the number,
## we can save them in a list and
## print the day on that number
day =["0","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
## Creating an instance
x = datetime.today() ## or use datetime.now()
d = x.isoweekday()
print("Today's isoweekday number is:", d)
print("Today's day is:",day[d])
x = datetime(2010, 1, 1)
print("Day on", x.year,"new year was:", day[x.isoweekday()])
x = datetime(2011, 1, 1)
print("Day on", x.year,"new year will be:", day[x.isoweekday()])
Output
输出量
Today's isoweekday number is: 5
Today's day is: Friday
Day on 2010 new year was: Friday
Day on 2011 new year will be: Saturday
翻译自: https://www.includehelp.com/python/datetime-isoweekday-method-with-example.aspx