Python-基础(6.1)-datetime and calendar

主要涉及的模块Modules

Jupter notebook NBViewer传送门

  • datetime Fast implementation of the datetime type. datetime提供操作日期和时间相关的类型
  • calendar Calendar printing functions. calendar模块提供和日历操作及显示打印相关的类
  • time This module provides various functions to manipulate time values. time模块提供了很多方法工具,用来操作时间相关的类型。

datetime模块

模块中包含的类

  • datetime(builtins.object)
    • date
      • datetime
    • time
    • timedelta
    • tzinfo
      • timezone

class datetime.date(year, month, day)

1
2
3
4
5
6
7
代表一个理想化的Gregorian日历中的日期,包括年、月、日等属性。
An idealized naive date, assuming the current Gregorian calendar always was, and always will be, in effect. Attributes: year, month, and day.
All arguments are required. Arguments may be integers, in the following ranges:

MINYEAR <= year <= MAXYEAR
1 <= month <= 12
1 <= day <= number of days in the given month and year

class methods:

classmethod date.today()

Return the current local date. This is equivalent to date.fromtimestamp(time.time()).

classmethod date.fromtimestamp(timestamp)

Return the local date corresponding to the POSIX timestamp, such as is returned by time.time(). This may raise OverflowError, if the timestamp is out of the range of values supported by the platform C localtime() function, and OSError on localtime() failure. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp().

Changed in version 3.3: Raise OverflowError instead of ValueError if the timestamp is out of the range of values supported by the platform C localtime() function. Raise OSError instead of ValueError on localtime() failure.

classmethod date.fromordinal(ordinal)

Return the date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= date.max.toordinal(). For any date d, date.fromordinal(d.toordinal()) == d.

classmethod date.fromisoformat(date_string)

Return a date corresponding to a date_string in the format emitted by date.isoformat(). Specifically, this function supports strings in the format(s) YYYY-MM-DD.

Caution This does not support parsing arbitrary ISO 8601 strings - it is only intended as the inverse operation of date.isoformat().
New in version 3.7.

Instance methods:

date.replace(year=self.year, month=self.month, day=self.day)
date.timetuple()

Return a time.struct_time such as returned by time.localtime(). The hours, minutes and seconds are 0, and the DST flag is -1. d.timetuple() is equivalent to time.struct_time((d.year, d.month, d.day, 0, 0, 0, d.weekday(), yday, -1)), where yday = d.toordinal() - date(d.year, 1, 1).toordinal() + 1 is the day number within the current year starting with 1 for January 1st.

date.toordinal()

Return the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. For any date object d, date.fromordinal(d.toordinal()) == d.

date.weekday()

Return the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, date(2002, 12, 4).weekday() == 2, a Wednesday. See also isoweekday().

date.isoweekday()

Return the day of the week as an integer, where Monday is 1 and Sunday is 7. For example, date(2002, 12, 4).isoweekday() == 3, a Wednesday. See also weekday(), isocalendar().

date.isocalendar()

Return a 3-tuple, (ISO year, ISO week number, ISO weekday).
The ISO calendar is a widely used variant of the Gregorian calendar. See https://www.staff.science.uu.nl/~gent0113/calendar/isocalendar.htm for a good explanation.

The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.

For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004, so that date(2003, 12, 29).isocalendar() == (2004, 1, 1) and date(2004, 1, 4).isocalendar() == (2004, 1, 7).

date.isoformat()

Return a string representing the date in ISO 8601 format, ‘YYYY-MM-DD’. For example, date(2002, 12, 4).isoformat() == ‘2002-12-04’.

date.str()

For a date d, str(d) is equivalent to d.isoformat().

date.ctime()

Return a string representing the date, for example date(2002, 12, 4).ctime() == ‘Wed Dec 4 00:00:00 2002’. d.ctime() is equivalent to time.ctime(time.mktime(d.timetuple())) on platforms where the native C ctime() function (which time.ctime() invokes, but which date.ctime() does not invoke) conforms to the C standard.

date.strftime(format)

Return a string representing the date, controlled by an explicit format string. Format codes referring to hours, minutes or seconds will see 0 values. For a complete list of formatting directives, see strftime() and strptime() Behavior.

date.format(format)

Same as date.strftime(). This makes it possible to specify a format string for a date object in formatted string literals and when using str.format(). For a complete list of formatting directives, see strftime() and strptime() Behavior.

example

1
2
3
4
5
6
7
8
9
10
11
12
from datetime import date
dToday = date.today()

print(dToday)
print(dToday.timetuple())
print(dToday.isoformat())
print(dToday.strftime("%d/%m/%Y"))
print(dToday.strftime("%A %d. %B %Y"))


dBirthday = date(date.today().year, 6, 24)
dBirthday.toordinal() # Days from 0001/01/01
2019-04-24
time.struct_time(tm_year=2019, tm_mon=4, tm_mday=24, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=114, tm_isdst=-1)
2019-04-24
24/04/2019
Wednesday 24. April 2019





737234

class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

1
2
3
4
5
6
7
8
9
10
The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be integers, in the following ranges:

MINYEAR <= year <= MAXYEAR,
1 <= month <= 12,
1 <= day <= number of days in the given month and year,
0 <= hour < 24,
0 <= minute < 60,
0 <= second < 60,
0 <= microsecond < 1000000,
fold in [0, 1].

class methods:

classmethod datetime.now(tz=None)
classmethod datetime.utcnow()
classmethod datetime.fromtimestamp(timestamp, tz=None)
classmethod datetime.fromordinal(ordinal)
classmethod datetime.combine(date, time, tzinfo=self.tzinfo)
classmethod datetime.fromisoformat(date_string)

Instance methods:

example of using datetime

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from datetime import datetime, date, time

d = date(2019, 4, 24)
t = time(12, 30)
print('combined data/time.' ,datetime.combine(d, t))

# Using datetime.now() or datetime.utcnow()
tNow = datetime.now()
utNow = datetime.utcnow()
print(tNow)
print(utNow)

## Using datetime.strptime()
dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
print(type(dt))
print(dt)

tt = dt.timetuple()

for i in tt:
print(i)

## format datetime to format string
dt.strftime("%A, %d. %B %Y %I:%M%p")
combined data/time. 2019-04-24 12:30:00
2019-04-24 11:24:26.485213
2019-04-24 03:24:26.485241
<class 'datetime.datetime'>
2006-11-21 16:30:00
2006
11
21
16
30
0
1
325
-1





'Tuesday, 21. November 2006 04:30PM'

example of using datetime with tzinfo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from datetime import timedelta, datetime, tzinfo

class GMT1(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=1) + self.dst(dt)
def dst(self, dt):
# DST starts last Sunday in March
d = datetime(dt.year, 4, 1) # ends last Sunday in October
self.dston = d - timedelta(days=d.weekday() + 1)
d = datetime(dt.year, 11, 1)
self.dstoff = d - timedelta(days=d.weekday() + 1)
if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
return timedelta(hours=1)
else:
return timedelta(0)
def tzname(self,dt):
return "GMT +1"

class GMT2(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=2) + self.dst(dt)
def dst(self, dt):
d = datetime(dt.year, 4, 1)
self.dston = d - timedelta(days=d.weekday() + 1)
d = datetime(dt.year, 11, 1)
self.dstoff = d - timedelta(days=d.weekday() + 1)
if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
return timedelta(hours=1)
else:
return timedelta(0)
def tzname(self,dt):
return "GMT +2"

gmt1 = GMT1()

class datetime.time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

1
2
3
4
5
6
7
8
All arguments are optional. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be integers, in the following ranges:

0 <= hour < 24,
0 <= minute < 60,
0 <= second < 60,
0 <= microsecond < 1000000,
fold in [0, 1].
If an argument outside those ranges is given, ValueError is raised. All default to 0 except tzinfo, which defaults to None.

classmethod time.fromisoformat(time_string)

Return a time corresponding to a time_string in one of the formats emitted by time.isoformat(). Specifically, this function supports strings in the format(s) HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]].

Instance methods:

time.replace(hour=self.hour, minute=self.minute, second=self.second, microsecond=self.microsecond, tzinfo=self.tzinfo, * fold=0)
time.isoformat(timespec=’auto’)
time.strftime(format)
time.tzname()

example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import time, tzinfo, timedelta
class GMT1(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=1)
def dst(self, dt):
return timedelta(0)
def tzname(self,dt):
return "Europe/Prague"

t = time(12, 10, 30, tzinfo=GMT1())
print(t) # doctest: +ELLIPSIS
#datetime.time(12, 10, 30, tzinfo=<GMT1 object at 0x...>)
gmt = GMT1()

print(t.isoformat())
#'12:10:30+01:00'

print(t.dst())
#datetime.timedelta(0)

print(t.tzname())
#'Europe/Prague'

print(t.strftime("%H:%M:%S %Z"))
#'12:10:30 Europe/Prague'

print('The {} is {:%H:%M}.'.format("time", t))
#'The time is 12:10.'
12:10:30+01:00
12:10:30+01:00
0:00:00
Europe/Prague
12:10:30 Europe/Prague
The time is 12:10.

class datetime.tzinfo (abstract base class, for datetime use)

class datetime.timezone(offset, name=None)

class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

A timedelta object represents a duration, the difference between two dates or times.

strftime() and strptime() Behavior

date, datetime, and time objects all support a strftime(format) method, to create a string representing the time under the control of an explicit format string. Broadly speaking, d.strftime(fmt) acts like the time module’s time.strftime(fmt, d.timetuple()) although not all objects support a timetuple() method.

  • 实例方法, data、datetime、time这三个实例,都支持 strftime(format)方法,将实例代表的时间,格式化成对应的字符串。

Conversely, the datetime.strptime() class method creates a datetime object from a string representing a date and time and a corresponding format string. datetime.strptime(date_string, format) is equivalent to datetime(*(time.strptime(date_string, format)[0:6])), except when the format includes sub-second components or timezone offset information, which are supported in datetime.strptime but are discarded by time.strptime.

类似的、time、date 也有类似的类方法

calendar模块

calendar - Calendar printing functions

模块中包含的类

  • builtins.ValueError(builtins.Exception)
    • IllegalMonthError
    • IllegalWeekdayError
  • builtins.object
    • Calendar
      • HTMLCalendar
        • LocaleHTMLCalendar
      • TextCalendar
        • LocaleTextCalendar
1
2
import calendar
help(calendar)
Help on module calendar:

NAME
    calendar - Calendar printing functions

MODULE REFERENCE
    https://docs.python.org/3.7/library/calendar

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    Note when comparing these calendars to the ones printed by cal(1): 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 (0=Monday, 6=Sunday).

CLASSES
    builtins.ValueError(builtins.Exception)
        IllegalMonthError
        IllegalWeekdayError
    builtins.object
        Calendar
            HTMLCalendar
                LocaleHTMLCalendar
            TextCalendar
                LocaleTextCalendar

    class Calendar(builtins.object)
     |  Calendar(firstweekday=0)
     |  
     |  Base calendar class. This class doesn't do any formatting. It simply
     |  provides data to subclasses.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, firstweekday=0)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  getfirstweekday(self)
     |  
     |  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.
     |  
     |  itermonthdays(self, year, month)
     |      Like itermonthdates(), but will yield day numbers. For days outside
     |      the specified month the day number is 0.
     |  
     |  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.
     |  
     |  itermonthdays3(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day) tuples.  Can be
     |      used for dates outside of datetime.date range.
     |  
     |  itermonthdays4(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
     |      Can be used for dates outside of datetime.date range.
     |  
     |  iterweekdays(self)
     |      Return an iterator for one week of weekday numbers starting with the
     |      configured first one.
     |  
     |  monthdatescalendar(self, year, month)
     |      Return a matrix (list of lists) representing a month's calendar.
     |      Each row represents a week; week entries are datetime.date values.
     |  
     |  monthdays2calendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; week entries are
     |      (day number, weekday number) tuples. Day numbers outside this month
     |      are zero.
     |  
     |  monthdayscalendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; days outside this month are zero.
     |  
     |  setfirstweekday(self, firstweekday)
     |  
     |  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.
     |      Each month contains between 4 and 6 weeks and each week contains 1-7
     |      days. Days are datetime.date objects.
     |  
     |  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 are
     |      zero.
     |  
     |  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.
     |      Day numbers outside this month are zero.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  firstweekday

    class HTMLCalendar(Calendar)
     |  HTMLCalendar(firstweekday=0)
     |  
     |  This calendar returns complete HTML pages.
     |  
     |  Method resolution order:
     |      HTMLCalendar
     |      Calendar
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  formatday(self, day, weekday)
     |      Return a day as a table cell.
     |  
     |  formatmonth(self, theyear, themonth, withyear=True)
     |      Return a formatted month as a table.
     |  
     |  formatmonthname(self, theyear, themonth, withyear=True)
     |      Return a month name as a table row.
     |  
     |  formatweek(self, theweek)
     |      Return a complete week as a table row.
     |  
     |  formatweekday(self, day)
     |      Return a weekday name as a table header.
     |  
     |  formatweekheader(self)
     |      Return a header for a week as a table row.
     |  
     |  formatyear(self, theyear, width=3)
     |      Return a formatted year as a table of tables.
     |  
     |  formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)
     |      Return a formatted year as a complete HTML page.
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  cssclass_month = 'month'
     |  
     |  cssclass_month_head = 'month'
     |  
     |  cssclass_noday = 'noday'
     |  
     |  cssclass_year = 'year'
     |  
     |  cssclass_year_head = 'year'
     |  
     |  cssclasses = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
     |  
     |  cssclasses_weekday_head = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', '...
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Calendar:
     |  
     |  __init__(self, firstweekday=0)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  getfirstweekday(self)
     |  
     |  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.
     |  
     |  itermonthdays(self, year, month)
     |      Like itermonthdates(), but will yield day numbers. For days outside
     |      the specified month the day number is 0.
     |  
     |  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.
     |  
     |  itermonthdays3(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day) tuples.  Can be
     |      used for dates outside of datetime.date range.
     |  
     |  itermonthdays4(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
     |      Can be used for dates outside of datetime.date range.
     |  
     |  iterweekdays(self)
     |      Return an iterator for one week of weekday numbers starting with the
     |      configured first one.
     |  
     |  monthdatescalendar(self, year, month)
     |      Return a matrix (list of lists) representing a month's calendar.
     |      Each row represents a week; week entries are datetime.date values.
     |  
     |  monthdays2calendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; week entries are
     |      (day number, weekday number) tuples. Day numbers outside this month
     |      are zero.
     |  
     |  monthdayscalendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; days outside this month are zero.
     |  
     |  setfirstweekday(self, firstweekday)
     |  
     |  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.
     |      Each month contains between 4 and 6 weeks and each week contains 1-7
     |      days. Days are datetime.date objects.
     |  
     |  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 are
     |      zero.
     |  
     |  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.
     |      Day numbers outside this month are zero.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Calendar:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  firstweekday

    class IllegalMonthError(builtins.ValueError)
     |  IllegalMonthError(month)
     |  
     |  Inappropriate argument value (of correct type).
     |  
     |  Method resolution order:
     |      IllegalMonthError
     |      builtins.ValueError
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, month)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  __str__(self)
     |      Return str(self).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.ValueError:
     |  
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |  
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |  
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |  
     |  __reduce__(...)
     |      Helper for pickle.
     |  
     |  __repr__(self, /)
     |      Return repr(self).
     |  
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |  
     |  __setstate__(...)
     |  
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |  
     |  __cause__
     |      exception cause
     |  
     |  __context__
     |      exception context
     |  
     |  __dict__
     |  
     |  __suppress_context__
     |  
     |  __traceback__
     |  
     |  args

    class IllegalWeekdayError(builtins.ValueError)
     |  IllegalWeekdayError(weekday)
     |  
     |  Inappropriate argument value (of correct type).
     |  
     |  Method resolution order:
     |      IllegalWeekdayError
     |      builtins.ValueError
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, weekday)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  __str__(self)
     |      Return str(self).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.ValueError:
     |  
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |  
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |  
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |  
     |  __reduce__(...)
     |      Helper for pickle.
     |  
     |  __repr__(self, /)
     |      Return repr(self).
     |  
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |  
     |  __setstate__(...)
     |  
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |  
     |  __cause__
     |      exception cause
     |  
     |  __context__
     |      exception context
     |  
     |  __dict__
     |  
     |  __suppress_context__
     |  
     |  __traceback__
     |  
     |  args

    class LocaleHTMLCalendar(HTMLCalendar)
     |  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. If this locale includes
     |  an encoding all strings containing month and weekday names will be returned
     |  as unicode.
     |  
     |  Method resolution order:
     |      LocaleHTMLCalendar
     |      HTMLCalendar
     |      Calendar
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, firstweekday=0, locale=None)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  formatmonthname(self, theyear, themonth, withyear=True)
     |      Return a month name as a table row.
     |  
     |  formatweekday(self, day)
     |      Return a weekday name as a table header.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from HTMLCalendar:
     |  
     |  formatday(self, day, weekday)
     |      Return a day as a table cell.
     |  
     |  formatmonth(self, theyear, themonth, withyear=True)
     |      Return a formatted month as a table.
     |  
     |  formatweek(self, theweek)
     |      Return a complete week as a table row.
     |  
     |  formatweekheader(self)
     |      Return a header for a week as a table row.
     |  
     |  formatyear(self, theyear, width=3)
     |      Return a formatted year as a table of tables.
     |  
     |  formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)
     |      Return a formatted year as a complete HTML page.
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from HTMLCalendar:
     |  
     |  cssclass_month = 'month'
     |  
     |  cssclass_month_head = 'month'
     |  
     |  cssclass_noday = 'noday'
     |  
     |  cssclass_year = 'year'
     |  
     |  cssclass_year_head = 'year'
     |  
     |  cssclasses = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
     |  
     |  cssclasses_weekday_head = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', '...
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Calendar:
     |  
     |  getfirstweekday(self)
     |  
     |  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.
     |  
     |  itermonthdays(self, year, month)
     |      Like itermonthdates(), but will yield day numbers. For days outside
     |      the specified month the day number is 0.
     |  
     |  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.
     |  
     |  itermonthdays3(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day) tuples.  Can be
     |      used for dates outside of datetime.date range.
     |  
     |  itermonthdays4(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
     |      Can be used for dates outside of datetime.date range.
     |  
     |  iterweekdays(self)
     |      Return an iterator for one week of weekday numbers starting with the
     |      configured first one.
     |  
     |  monthdatescalendar(self, year, month)
     |      Return a matrix (list of lists) representing a month's calendar.
     |      Each row represents a week; week entries are datetime.date values.
     |  
     |  monthdays2calendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; week entries are
     |      (day number, weekday number) tuples. Day numbers outside this month
     |      are zero.
     |  
     |  monthdayscalendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; days outside this month are zero.
     |  
     |  setfirstweekday(self, firstweekday)
     |  
     |  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.
     |      Each month contains between 4 and 6 weeks and each week contains 1-7
     |      days. Days are datetime.date objects.
     |  
     |  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 are
     |      zero.
     |  
     |  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.
     |      Day numbers outside this month are zero.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Calendar:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  firstweekday

    class LocaleTextCalendar(TextCalendar)
     |  LocaleTextCalendar(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. If this locale includes
     |  an encoding all strings containing month and weekday names will be returned
     |  as unicode.
     |  
     |  Method resolution order:
     |      LocaleTextCalendar
     |      TextCalendar
     |      Calendar
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, firstweekday=0, locale=None)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  formatmonthname(self, theyear, themonth, width, withyear=True)
     |      Return a formatted month name.
     |  
     |  formatweekday(self, day, width)
     |      Returns a formatted week day name.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from TextCalendar:
     |  
     |  formatday(self, day, weekday, width)
     |      Returns a formatted day.
     |  
     |  formatmonth(self, theyear, themonth, w=0, l=0)
     |      Return a month's calendar string (multi-line).
     |  
     |  formatweek(self, theweek, width)
     |      Returns a single week in a string (no newline).
     |  
     |  formatweekheader(self, width)
     |      Return a header for a week.
     |  
     |  formatyear(self, theyear, w=2, l=1, c=6, m=3)
     |      Returns a year's calendar as a multi-line string.
     |  
     |  prmonth(self, theyear, themonth, w=0, l=0)
     |      Print a month's calendar.
     |  
     |  prweek(self, theweek, width)
     |      Print a single week (no newline).
     |  
     |  pryear(self, theyear, w=0, l=0, c=6, m=3)
     |      Print a year's calendar.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Calendar:
     |  
     |  getfirstweekday(self)
     |  
     |  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.
     |  
     |  itermonthdays(self, year, month)
     |      Like itermonthdates(), but will yield day numbers. For days outside
     |      the specified month the day number is 0.
     |  
     |  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.
     |  
     |  itermonthdays3(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day) tuples.  Can be
     |      used for dates outside of datetime.date range.
     |  
     |  itermonthdays4(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
     |      Can be used for dates outside of datetime.date range.
     |  
     |  iterweekdays(self)
     |      Return an iterator for one week of weekday numbers starting with the
     |      configured first one.
     |  
     |  monthdatescalendar(self, year, month)
     |      Return a matrix (list of lists) representing a month's calendar.
     |      Each row represents a week; week entries are datetime.date values.
     |  
     |  monthdays2calendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; week entries are
     |      (day number, weekday number) tuples. Day numbers outside this month
     |      are zero.
     |  
     |  monthdayscalendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; days outside this month are zero.
     |  
     |  setfirstweekday(self, firstweekday)
     |  
     |  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.
     |      Each month contains between 4 and 6 weeks and each week contains 1-7
     |      days. Days are datetime.date objects.
     |  
     |  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 are
     |      zero.
     |  
     |  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.
     |      Day numbers outside this month are zero.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Calendar:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  firstweekday

    class TextCalendar(Calendar)
     |  TextCalendar(firstweekday=0)
     |  
     |  Subclass of Calendar that outputs a calendar as a simple plain text
     |  similar to the UNIX program cal.
     |  
     |  Method resolution order:
     |      TextCalendar
     |      Calendar
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  formatday(self, day, weekday, width)
     |      Returns a formatted day.
     |  
     |  formatmonth(self, theyear, themonth, w=0, l=0)
     |      Return a month's calendar string (multi-line).
     |  
     |  formatmonthname(self, theyear, themonth, width, withyear=True)
     |      Return a formatted month name.
     |  
     |  formatweek(self, theweek, width)
     |      Returns a single week in a string (no newline).
     |  
     |  formatweekday(self, day, width)
     |      Returns a formatted week day name.
     |  
     |  formatweekheader(self, width)
     |      Return a header for a week.
     |  
     |  formatyear(self, theyear, w=2, l=1, c=6, m=3)
     |      Returns a year's calendar as a multi-line string.
     |  
     |  prmonth(self, theyear, themonth, w=0, l=0)
     |      Print a month's calendar.
     |  
     |  prweek(self, theweek, width)
     |      Print a single week (no newline).
     |  
     |  pryear(self, theyear, w=0, l=0, c=6, m=3)
     |      Print a year's calendar.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from Calendar:
     |  
     |  __init__(self, firstweekday=0)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  getfirstweekday(self)
     |  
     |  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.
     |  
     |  itermonthdays(self, year, month)
     |      Like itermonthdates(), but will yield day numbers. For days outside
     |      the specified month the day number is 0.
     |  
     |  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.
     |  
     |  itermonthdays3(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day) tuples.  Can be
     |      used for dates outside of datetime.date range.
     |  
     |  itermonthdays4(self, year, month)
     |      Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.
     |      Can be used for dates outside of datetime.date range.
     |  
     |  iterweekdays(self)
     |      Return an iterator for one week of weekday numbers starting with the
     |      configured first one.
     |  
     |  monthdatescalendar(self, year, month)
     |      Return a matrix (list of lists) representing a month's calendar.
     |      Each row represents a week; week entries are datetime.date values.
     |  
     |  monthdays2calendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; week entries are
     |      (day number, weekday number) tuples. Day numbers outside this month
     |      are zero.
     |  
     |  monthdayscalendar(self, year, month)
     |      Return a matrix representing a month's calendar.
     |      Each row represents a week; days outside this month are zero.
     |  
     |  setfirstweekday(self, firstweekday)
     |  
     |  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.
     |      Each month contains between 4 and 6 weeks and each week contains 1-7
     |      days. Days are datetime.date objects.
     |  
     |  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 are
     |      zero.
     |  
     |  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.
     |      Day numbers outside this month are zero.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Calendar:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  firstweekday

FUNCTIONS
    calendar = formatyear(theyear, w=2, l=1, c=6, m=3) method of TextCalendar instance
        Returns a year's calendar as a multi-line string.

    firstweekday = getfirstweekday() method of TextCalendar instance

    isleap(year)
        Return True for leap years, False for non-leap years.

    leapdays(y1, y2)
        Return number of leap years in range [y1, y2).
        Assume y1 <= y2.

    month = formatmonth(theyear, themonth, w=0, l=0) method of TextCalendar instance
        Return a month's calendar string (multi-line).

    monthcalendar = monthdayscalendar(year, month) method of TextCalendar instance
        Return a matrix representing a month's calendar.
        Each row represents a week; days outside this month are zero.

    monthrange(year, month)
        Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for
        year, month.

    prcal = pryear(theyear, w=0, l=0, c=6, m=3) method of TextCalendar instance
        Print a year's calendar.

    prmonth(theyear, themonth, w=0, l=0) method of TextCalendar instance
        Print a month's calendar.

    setfirstweekday(firstweekday)

    timegm(tuple)
        Unrelated but handy function to calculate Unix timestamp from GMT.

    weekday(year, month, day)
        Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31).

    weekheader = formatweekheader(width) method of TextCalendar instance
        Return a header for a week.

DATA
    __all__ = ['IllegalMonthError', 'IllegalWeekdayError', 'setfirstweekda...
    day_abbr = <calendar._localized_day object>
    day_name = <calendar._localized_day object>
    month_abbr = <calendar._localized_month object>
    month_name = <calendar._localized_month object>

FILE
    /home/yutianc/miniconda3/lib/python3.7/calendar.py