日曆模塊允許輸出類似於程序的日曆,並提供與日曆相關的其他有用函數。 “日曆”模塊中定義的函數和類使用理想化的日曆,當前的公曆日曆在兩個方向上都無限期擴展。
itermonthdates()方法返回一年中月份(1-12)的迭代器。該迭代器將返回該月的所有天,以及返回一個整周所需的月初或月末之後的所有天。
用法: itermonthdates(year, month) 參數: year: year of the calendar month: month of the calendar 返回: an iterator for the month.
代碼1:
# Python program to demonstrate working
# of itermonthdates() method
# importing calendar module
from calendar import Calendar
obj = calendar.Calendar()
# iteratign with itermonthdates
for day in obj.itermonthdates(2018, 9):
print(day)
輸出:
2018-08-27 2018-08-28 2018-08-29 2018-08-30 2018-08-31 . . . 2018-09-26 2018-09-27 2018-09-28 2018-09-29 2018-09-30
代碼2:
# Python program to demonstrate working
# of itermonthdates() method
# importing calendar module
import calendar
# use with firstweekday = 5
obj = calendar.Calendar(firstweekday = 5)
# iteratign with itermonthdates
for day in obj.itermonthdates(2018, 4):
print(day)
輸出:
2018-08-30 2018-08-31 2018-09-01 2018-09-02 2018-09-03 . . 2018-09-30 2018-10-01 2018-10-02 2018-10-03 2018-09-01 2018-09-02 2018-09-03 . . 2018-09-28 . . 0018-03-31 0018-04-01 0018-04-02 . . 2018-04-28 2018-04-29 2018-04-30 2018-05-01 2018-05-02
相關用法
- Python calendar yeardatescalendar()用法及代碼示例
- Python calendar yeardays2calendar()用法及代碼示例
- Python calendar monthdayscalendar()用法及代碼示例
- Python calendar monthdays2calendar()用法及代碼示例
- Python calendar yeardayscalendar()用法及代碼示例
- Python calendar leapdays()用法及代碼示例
- Python calendar isleap()用法及代碼示例
- Python calendar firstweekday()用法及代碼示例
- Python calendar setfirstweekday()用法及代碼示例
- Python calendar formatyear()用法及代碼示例
- Python calendar prmonth()用法及代碼示例
- Python calendar itermonthdays()用法及代碼示例
- Python calendar pryear()用法及代碼示例
- Python calendar iterweekdays()用法及代碼示例
- Python calendar itermonthdays2()用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python calendar module | itermonthdates() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。