Python datetime.weekday()方法 (Python datetime.weekday() Method)
datetime.weekday() method is used to manipulate objects of datetime class of module datetime.
datetime.weekday()方法用于操作模块datetime的datetime类的对象。
It uses a datetime class object and returns the day of the week as an integer, where Monday is 0 and Sunday is 6. It is an instance method, i.e., it works on an instance of the class.
它使用datetime类对象,并以整数形式返回星期几,其中Monday是0,Sunday是6。它是一个实例方法,即,它适用于该类的实例。
Module:
模块:
import datetime
Class:
类:
from datetime import datetime
Syntax:
句法:
weekday()
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
## Creating an instance
x = datetime.today()
d = x.weekday()
print("Today's weekday number is:", d)
x = datetime(1996, 10,27, 21, 5, 5)
d1 = x.weekday()
xd = x.date()
print("Weekday number on the date", xd,"will be:",d1)
print()
## Since we know the number,
## we can save them in a list and
## print the day on that number
day =["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
print("Today's day is:",day[d])
print("Day on date", x," was:", day[d1])
Output
输出量
Today's weekday number is: 5
Weekday number on the date 1996-10-27 will be: 6
Today's day is: Saturday
Day on date 1996-10-27 21:05:05 was: Sunday
翻译自: https://www.includehelp.com/python/datetime-weekday-method-with-example.aspx