On this page
calendar.LocaleHTMLCalendar
Prev: calendar.leapdays | Up: calendar | Next: calendar.LocaleTextCalendar
Rel: calendar.calendar, calendar.Calendar, calendar.Day, calendar.firstweekday
Ref: docs.python.org — calendar.LocaleHTMLCalendar
Tags: #public #python3 #stdlib #calendar
Import
import calendar
from calendar import LocaleHTMLCalendar
Signature & Overview
calendar.LocaleHTMLCalendar(firstweekday=0, locale=None)
This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale.
Methods & Attributes
LocaleHTMLCalendar.firstweekday(...)—LocaleHTMLCalendar.firstweekdaymethod/property.LocaleHTMLCalendar.formatday(self, day, weekday)— Return a day as a table cell.LocaleHTMLCalendar.formatmonth(self, theyear, themonth, withyear=True)— Return a formatted month as a table.LocaleHTMLCalendar.formatmonthname(self, theyear, themonth, withyear=True)—LocaleHTMLCalendar.formatmonthnamemethod/property.LocaleHTMLCalendar.formatweek(self, theweek)— Return a complete week as a table row.LocaleHTMLCalendar.formatweekday(self, day)—LocaleHTMLCalendar.formatweekdaymethod/property.LocaleHTMLCalendar.formatweekheader(self)— Return a header for a week as a table row.LocaleHTMLCalendar.formatyear(self, theyear, width=3)— Return a formatted year as a table of tables.LocaleHTMLCalendar.formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)— Return a formatted year as a complete HTML page.LocaleHTMLCalendar.getfirstweekday(self)—LocaleHTMLCalendar.getfirstweekdaymethod/property.LocaleHTMLCalendar.itermonthdates(self, year, month)— Return an iterator for one month. The iterator will yield datetime.date values and will always iterate through complete weeks, so it will yield dates outside the specified month.LocaleHTMLCalendar.itermonthdays(self, year, month)— Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0.LocaleHTMLCalendar.itermonthdays2(self, year, month)— Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0.LocaleHTMLCalendar.itermonthdays3(self, year, month)— Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range.LocaleHTMLCalendar.itermonthdays4(self, year, month)— Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.LocaleHTMLCalendar.iterweekdays(self)— Return an iterator for one week of weekday numbers starting with the configured first one.LocaleHTMLCalendar.monthdatescalendar(self, year, month)— Return a matrix (list of lists) representing a month's calendar.LocaleHTMLCalendar.monthdays2calendar(self, year, month)— Return a matrix representing a month's calendar.LocaleHTMLCalendar.monthdayscalendar(self, year, month)— Return a matrix representing a month's calendar.LocaleHTMLCalendar.setfirstweekday(self, firstweekday)—LocaleHTMLCalendar.setfirstweekdaymethod/property.LocaleHTMLCalendar.yeardatescalendar(self, year, width=3)— Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months.LocaleHTMLCalendar.yeardays2calendar(self, year, width=3)— Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are (day number, weekday number) tuples. Day numbers outside this month areLocaleHTMLCalendar.yeardayscalendar(self, year, width=3)— Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are day numbers.
Usage
import calendar
html = calendar.LocaleHTMLCalendar().formatmonth(2026, 12)
assert "<table" in html
Gotchas
- Mutates process-global
localetemporarily: Not thread-safe in multi-threaded web servers.
REPL Inspect
from calendar import LocaleHTMLCalendar
help(LocaleHTMLCalendar)
Linked from
Related notes
- tuts/python3/stdlib_module/calendar/leapdays Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/LocaleTextCalendar Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/calendar Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Calendar_class Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Day Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/firstweekday Linked here; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/calendar/HTMLCalendar shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/IllegalMonthError shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/IllegalWeekdayError shared tags: #calendar, #stdlib