Python calendar Module
Example
Check leap year and weekday of a date:
import calendar
print(calendar.isleap(2024))
print(calendar.weekday(2025, 1, 1))
Try it Yourself »
Definition and Usage
The calendar module outputs calendars and provides useful calendar-related functions.
Use it to format months/years, compute weekdays, and work with leap years and other calendar data.
Members
Member | Description |
---|---|
Calendar | Base class for calendar calculations and iterators. |
calendar() | Return a year’s calendar as a multi-line string. |
day_abbr | Sequence with abbreviated weekday names. |
day_name | Sequence with localized weekday names. |
firstweekday() | Get current setting for the first weekday. |
HTMLCalendar | Class for generating HTML calendars. |
isleap() | Return True for leap years, False otherwise. |
leapdays() | Return the number of leap years in a range of years. |
LocaleHTMLCalendar | HTML calendar that uses locale-specific month and weekday names. |
LocaleTextCalendar | Text calendar that uses locale-specific month and weekday names. |
month() | Return a month calendar as a multi-line string. |
month_abbr | Sequence with abbreviated month names. |
month_name | Sequence with localized month names. |
monthcalendar() | Return matrix representation of a month. |
monthrange() | Return weekday of first day of the month and number of days. |
prcal() | Print a year’s calendar. |
prmonth() | Print a month calendar. |
setfirstweekday() | Set first weekday (0=Monday, 6=Sunday). |
TextCalendar | Class for generating plain text calendars. |
weekday() | Return weekday (0=Monday..6=Sunday) for a date. |
weekheader() | Return a header string with abbreviated weekday names. |