python 示例
Python Calendar.itermonthdates()方法 (Python Calendar.itermonthdates() Method)
Calendar.itermonthdates() method is an inbuilt method of the Calendar class of calendar module in Python. It uses an instance of this class and returns an iterator for the given month(1–12) in the given year. The iterator will return all days (as datetime.date objects) for the month and all days before the start of the month or after the end of the month that are required to get a complete week.
Calendar.itermonthdates()方法是Python中Calendar模块的Calendar类的内置方法。 它使用此类的实例,并返回给定年份中给定月(1–12)的迭代器。 迭代器将返回该月的所有天(作为datetime.date对象)以及该月初或该月末之后整整一周所需的所有天。
Module:
模块:
import calendar
Class:
类:
from calendar import Calendar
Syntax:
句法:
itermonthdates(year, month)
Parameter(s):
参数:
year: represents the year of the calendar
年 :代表日历的年份
month: represents month of the calendar
month :代表日历的月份
Return value:
返回值:
The function returns an iterator for the given month of the given year.
该函数返回给定年份中给定月份的迭代器。
Example:
例:
# Python program to illustrate the
# use of itermonthdates() method
# import class
import calendar
# Creating Calendar Instance
cal = calendar.Calendar()
year = 2020
month = 2
# Complete weeks will be printed
for i in cal.itermonthdates(year, month):
print(i)
print()
# Setting firstweekday value to 3
cal = calendar.Calendar(firstweekday = 3)
year = 2016
month = 2
for i in cal.itermonthdates(year, month):
print(i)
Output
输出量
2020-01-27
2020-01-28
2020-01-29
2020-01-30
2020-01-31
2020-02-01
2020-02-02
2020-02-03
2020-02-04
2020-02-05
2020-02-06
2020-02-07
2020-02-08
2020-02-09
2020-02-10
2020-02-11
2020-02-12
2020-02-13
2020-02-14
2020-02-15
2020-02-16
2020-02-17
2020-02-18
2020-02-19
2020-02-20
2020-02-21
2020-02-22
2020-02-23
2020-02-24
2020-02-25
2020-02-26
2020-02-27
2020-02-28
2020-02-29
2020-03-01
2016-01-28
2016-01-29
2016-01-30
2016-01-31
2016-02-01
2016-02-02
2016-02-03
2016-02-04
2016-02-05
2016-02-06
2016-02-07
2016-02-08
2016-02-09
2016-02-10
2016-02-11
2016-02-12
2016-02-13
2016-02-14
2016-02-15
2016-02-16
2016-02-17
2016-02-18
2016-02-19
2016-02-20
2016-02-21
2016-02-22
2016-02-23
2016-02-24
2016-02-25
2016-02-26
2016-02-27
2016-02-28
2016-02-29
2016-03-01
2016-03-02
Reference: calendar.Calendar.itermonthdates
参考: calendar.Calendar.itermonthdates
翻译自: https://www.includehelp.com/python/calendar-calendar-itermonthdates-method-with-example.aspx
python 示例