calendar
— 一般日历相关函数
¶
源代码: Lib/calendar.py
This module allows you to output calendars like the Unix
cal
program, and provides additional useful functions related to the calendar. By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention). Use
setfirstweekday()
to set the first day of the week to Sunday (6) or to any other weekday. Parameters that specify dates are given as integers. For related functionality, see also the
datetime
and
time
模块。
The functions and classes defined in this module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions. This matches the definition of the “proleptic Gregorian” calendar in Dershowitz and Reingold’s book “Calendrical Calculations”, where it’s the base calendar for all computations. Zero and negative years are interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is 2 BC, and so on.
- class calendar. Calendar ( firstweekday = 0 ) ¶
-
创建
Calendar对象。 firstweekday is an integer specifying the first day of the week.MONDAYis0(默认),SUNDAYis6.A
Calendarobject provides several methods that can be used for preparing the calendar data for formatting. This class doesn’t do any formatting itself. This is the job of subclasses.Calendar实例具有下列方法:- iterweekdays ( ) ¶
-
Return an iterator for the week day numbers that will be used for one week. The first value from the iterator will be the same as the value of the
firstweekday特性。
- itermonthdates ( year , month ) ¶
-
Return an iterator for the month month (1–12) in the year year . This iterator will return all days (as
datetime.dateobjects) 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.
- itermonthdays ( year , month ) ¶
-
Return an iterator for the month month in the year year similar to
itermonthdates(), but not restricted by thedatetime.daterange. Days returned will simply be day of the month numbers. For the days outside of the specified month, the day number is0.
- itermonthdays2 ( year , month ) ¶
-
Return an iterator for the month month in the year year similar to
itermonthdates(), but not restricted by thedatetime.daterange. Days returned will be tuples consisting of a day of the month number and a week day number.
- itermonthdays3 ( year , month ) ¶
-
Return an iterator for the month month in the year year similar to
itermonthdates(), but not restricted by thedatetime.daterange. Days returned will be tuples consisting of a year, a month and a day of the month numbers.3.7 版添加。