当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python date isoweekday()用法及代码示例


Python date.isoweekday() 方法

date.isoweekday() 方法用于操作模块 datetime 的日期类对象。

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

模块:

    import datetime

类:

    from datetime import date

用法:

    isoweekday()

参数:

  • None

返回值:

这个方法的返回类型是一个数字,它告诉我们那天是星期几。

例:

## 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()])

输出

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


相关用法


注:本文由纯净天空筛选整理自 Python date isoweekday() Method with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。