python 示例_Python date isoweekday()方法与示例

python 示例

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

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

date.isoweekday()方法用于处理模块日期时间的日期类的对象。

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

它使用日期类对象,并以整数形式返回星期几,其中星期一是1,星期日是7。它与date.weekday()函数相同,在函数中我们认为星期一是0,以后将递增1。天。 它是一个实例方法,因为它可用于date类的实例。

Module:

模块:

    import datetime

Class:

类:

    from datetime import date

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

## 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 = date.today()
d = x.isoweekday()
print("Today's isoweekday number is:", d)
print("Today's day is:",day[d])

x = date(2020, 1, 1)
print("Day on", x.year,"new year was:", day[x.isoweekday()])

x = date(2021, 1, 1)
print("Day on", x.year,"new year will be:", day[x.isoweekday()])

Output

输出量

Today's isoweekday number is: 3
Today's day is: Wednesday
Day on 2020 new year was: Wednesday
Day on 2021 new year will be: Friday


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

python 示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值