當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。