带有示例的Python date weekday()方法

Python date.weekday()方法 (Python date.weekday() Method)

date.weekday() method is used to manipulate objects of date class of module datetime.

date.weekday()方法用于操作模块日期时间的日期类的对象。

It uses a date 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.

它使用日期类对象,并以整数形式返回星期几,其中Monday是0,Sunday是6。它是一个实例方法。

Module:

模块:

    import datetime

Class:

类:

    from datetime import date

Syntax:

句法:

    weekday()

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 date class
from datetime import date

## Creating an instance
x = date.today()
d = x.weekday()
print("Today's weekday number is:", d)

x = date(2020, 10, 30)
d1 = x.weekday()
print("Weekday number on the date",x,"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," will be:", day[d1])

Output

输出量

Today's weekday number is: 2
Weekday number on the date 2020-10-30 will be: 4

Today's day is: Wednesday
Day on date 2020-10-30  will be: Friday


翻译自: https://www.includehelp.com/python/date-weekday-method-with-example.aspx

你可能感兴趣的:(python,java,django,ios)