📜  PythonDatetime.date类的isocalendar()函数

📅  最后修改于: 2022-05-13 01:55:14.113000             🧑  作者: Mango

PythonDatetime.date类的isocalendar()函数

isocalendar()函数用于返回包含 ISO 年、ISO 周数和 ISO 工作日的元组。

笔记:

  • 根据 ISO 标准 8601 和 ISO 标准 2015,星期四是一周的中间一天。
  • 因此,ISO 年总是从星期一开始。
  • ISO 年可以有 52 个整周或 53 个整周。
  • ISO 年在年初或年末没有任何小数周。

示例 1:获取 ISO 年份、ISO 周数和 ISO 工作日。

Python3
# Python3 code to demonstrate
# Getting a tuple of ISO Year, 
# ISO Week Number and ISO Weekday
  
# Importing date module from datetime
from datetime import date
   
# Calling the today() function
# to return todays date
Todays_date = date.today()
  
# Printing today's date
print(Todays_date)
  
# Calling the isocalendar() function
# over the above today's date to return
# its ISO Year, ISO Week Number
# and ISO Weekday
print(Todays_date.isocalendar())


Python3
# Python3 code to demonstrate
# Getting a tuple of ISO Year, 
# ISO Week Number and ISO Weekday
  
# Importing date module from datetime
from datetime import date
   
# Creating an instance for 
# different dates
A = date(2020, 10, 11)
  
# Calling the isocalendar() function
# over the above specified date
Date = A.isocalendar()
  
# Printing Original date and its 
# ISO Year, ISO Week Number
# and ISO Weekday
print("Original date:",A)
print("Date in isocalendar is:", Date)


输出:

2021-07-25
(2021, 29, 7)

示例 2:获取具有特定日期的 ISO 年份、ISO 周数和 ISO 工作日。

蟒蛇3

# Python3 code to demonstrate
# Getting a tuple of ISO Year, 
# ISO Week Number and ISO Weekday
  
# Importing date module from datetime
from datetime import date
   
# Creating an instance for 
# different dates
A = date(2020, 10, 11)
  
# Calling the isocalendar() function
# over the above specified date
Date = A.isocalendar()
  
# Printing Original date and its 
# ISO Year, ISO Week Number
# and ISO Weekday
print("Original date:",A)
print("Date in isocalendar is:", Date)

输出:

Original date: 2020-10-11
Date in isocalendar is: (2020, 41, 7)