|
| 1 | +.. currentmodule:: datetime |
| 2 | +.. _datetime.date: |
| 3 | + |
| 4 | +class date -- Represent a date |
| 5 | +=============================== |
| 6 | + |
| 7 | +:py:class:`~datetime.date` objects support equality and comparison operators. |
| 8 | + |
| 9 | +.. class:: date(year, month, day) |
| 10 | + |
| 11 | + All arguments are required. Arguments must be integers, in the following ranges: |
| 12 | + |
| 13 | + - :py:class:`~datetime.MINYEAR` <= year <= :py:class:`~datetime.MAXYEAR` |
| 14 | + - 1 <= month <= 12 |
| 15 | + - 1 <= day <= number of days in the given month and year |
| 16 | + |
| 17 | + Other constructors: |
| 18 | + |
| 19 | + .. classmethod:: today() |
| 20 | + |
| 21 | + .. classmethod:: fromtimestamp(timestamp) |
| 22 | + |
| 23 | + .. classmethod:: fromordinal(ordinal) |
| 24 | + |
| 25 | + .. classmethod:: fromisoformate(date_string) |
| 26 | + |
| 27 | + Class attributes: |
| 28 | + |
| 29 | + .. attribute:: min |
| 30 | + |
| 31 | + The earliest representable date, date(:py:attr:`~datetime.MINYEAR`, 1, 1). |
| 32 | + |
| 33 | + .. attribute:: max |
| 34 | + |
| 35 | + The latest representable date, date(:py:attr:`~datetime.MAXYEAR`, 12, 31). |
| 36 | + |
| 37 | + .. attribute:: resolution |
| 38 | + |
| 39 | + The smallest possible difference between non-equal date objects, ``timedelta(days=1)`` . |
| 40 | + |
| 41 | + Instance attributes: |
| 42 | + |
| 43 | + .. attribute:: year |
| 44 | + |
| 45 | + .. attribute:: month |
| 46 | + |
| 47 | + .. attribute:: day |
| 48 | + |
| 49 | + Instance methods |
| 50 | + |
| 51 | + .. method:: replace(year = self.year, month = self.month, day = self.day) |
| 52 | + |
| 53 | + Return a new :py:class:`~datetime.date` object with the same values but the specified parameters updated. |
| 54 | + |
| 55 | + .. method:: tuple() |
| 56 | + |
| 57 | + Return the date as a tuple (year, month, day) |
| 58 | + |
| 59 | + .. method:: timetuple() |
| 60 | + |
| 61 | + Return the date as a 9-tuple |
| 62 | + |
| 63 | + .. method:: toordinal() |
| 64 | + |
| 65 | + Return an integer representing the ordinal of the date, where January 1st of year 1 has ordinal 1. |
| 66 | + |
| 67 | + .. method:: isoformat() |
| 68 | + |
| 69 | + Return a string representing the date in ISO 8601 format, YYYY-MM-DD:: |
| 70 | + |
| 71 | + from datetime import date |
| 72 | + date(2002, 12, 4).isoformat() |
| 73 | + # outputs '2002-12-04' |
| 74 | + |
| 75 | + .. method:: isoweekday() |
| 76 | + |
| 77 | + Return the day of the week as an integer, where Monday is 1 and Sunday is 7. |
| 78 | + |
| 79 | + .. method:: weekday() |
| 80 | + |
| 81 | + Return the day of the week as an integer, where Monday is 0 and Sunday is 6. |
0 commit comments