datetime - Fast implementation of the datetime type.
| Use Case | Command | Description |
|---|---|---|
| π Create date | date(2025, 4, 15) | Construct a date object |
| π Create datetime | datetime(2025, 4, 15, 13, 30) | Construct a datetime object |
| β° Create time | time(13, 30, 0) | Construct a time object |
| β±οΈ Duration | timedelta(days=7) | Create a timedelta (7 days) |
| π Fixed offset | timezone(timedelta(hours=2)) | UTC+2 timezone |
| πΊπΈ Today | date.today() | Current local date |
| π Now | datetime.now() | Current local datetime |
| π UTC now | datetime.utcnow() | Current UTC datetime |
| π ISO format | d.isoformat() | Date to ISO string (YYYY-MM-DD) |
| π Parse string | datetime.strptime("2025-04-15", "%Y-%m-%d") | Parse datetime from string |
| π Timestamp | datetime.fromtimestamp(1712345678.0) | Create datetime from POSIX timestamp |
| π Arithmetic | d + timedelta(days=1) | Add one day to date |
https://docs.python.org/3.10/library/datetime.html
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.
builtins.object
date
datetime
time
timedelta
tzinfo
timezone
date(year, month, day) --> date object
__add__(self, value, /) β Return self+value.__eq__(self, value, /) β Return self==value.__format__(...) β Formats self with strftime.__ge__(self, value, /) β Return self>=value.__getattribute__(self, name, /) β Return getattr(self, name).__gt__(self, value, /) β Return self>value.__hash__(self, /) β Return hash(self).__le__(self, value, /) β Return self<=value.__lt__(self, value, /) β Return self<value.__ne__(self, value, /) β Return self!=value.__radd__(self, value, /) β Return value+self.__reduce__(...) β __reduce__() -> (cls, state)__repr__(self, /) β Return repr(self).__rsub__(self, value, /) β Return value-self.__str__(self, /) β Return str(self).__sub__(self, value, /) β Return self-value.ctime(...) β Return ctime() style string.isocalendar(...) β Return a named tuple containing ISO year, week number, and weekday.isoformat(...) β Return string in ISO 8601 format, YYYY-MM-DD.isoweekday(...) β Return the day of the week represented by the date. Monday == 1 ... Sunday == 7replace(...) β Return date with new specified fields.strftime(...) β format -> strftime() style string.timetuple(...) β Return time tuple, compatible with time.localtime().toordinal(...) β Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.weekday(...) β Return the day of the week represented by the date. Monday == 0 ... Sunday == 6fromisocalendar(...) β int, int, int -> Construct a date from the ISO year, week number and weekday. This is the inverse of the date.isocalendar() functionfromisoformat(...) β str -> Construct a date from the output of date.isoformat()fromordinal(...) β int -> date corresponding to a proleptic Gregorian ordinal.fromtimestamp(timestamp, /) β Create a date from a POSIX timestamp. The timestamp is a number, e.g. created via time.time(), that is interpreted as local time.today(...) β Current date or datetime: same as self.__class__.fromtimestamp(time.time()).__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.daymonthyearmax = datetime.date(9999, 12, 31)min = datetime.date(1, 1, 1)resolution = datetime.timedelta(days=1)datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.
Method resolution order: datetime, date, builtins.object
__add__(self, value, /) β Return self+value.__eq__(self, value, /) β Return self==value.__ge__(self, value, /) β Return self>=value.__getattribute__(self, name, /) β Return getattr(self, name).__gt__(self, value, /) β Return self>value.__hash__(self, /) β Return hash(self).__le__(self, value, /) β Return self<=value.__lt__(self, value, /) β Return self<value.__ne__(self, value, /) β Return self!=value.__radd__(self, value, /) β Return value+self.__reduce__(...) β __reduce__() -> (cls, state)__reduce_ex__(...) β __reduce_ex__(proto) -> (cls, state)__repr__(self, /) β Return repr(self).__rsub__(self, value, /) β Return value-self.__str__(self, /) β Return str(self).__sub__(self, value, /) β Return self-value.astimezone(...) β tz -> convert to local time in new timezone tzctime(...) β Return ctime() style string.date(...) β Return date object with same year, month and day.dst(...) β Return self.tzinfo.dst(self).isoformat(...) β [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to 'T'. The optional argument timespec specifies the number of additional terms of the time to include. Valid options are 'auto', 'hours', 'minutes', 'seconds', 'milliseconds' and 'microseconds'.replace(...) β Return datetime with new specified fields.time(...) β Return time object with same time but with tzinfo=None.timestamp(...) β Return POSIX timestamp as float.timetuple(...) β Return time tuple, compatible with time.localtime().timetz(...) β Return time object with same time and tzinfo.tzname(...) β Return self.tzinfo.tzname(self).utcoffset(...) β Return self.tzinfo.utcoffset(self).utctimetuple(...) β Return UTC time tuple, compatible with time.localtime().combine(...) β date, time -> datetime with same date and time fieldsfromisoformat(...) β string -> datetime from datetime.isoformat() outputfromtimestamp(...) β timestamp[, tz] -> tz's local time from POSIX timestamp.now(tz=None) β Returns new datetime object representing current time local to tz. If no tz is specified, uses local timezone.strptime(...) β string, format -> new datetime parsed from a string (like time.strptime()).utcfromtimestamp(...) β Construct a naive UTC datetime from a POSIX timestamp.utcnow(...) β Return a new datetime representing UTC day and time.__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.foldhourmicrosecondminutesecondtzinfomax = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)min = datetime.datetime(1, 1, 1, 0, 0)resolution = datetime.timedelta(microseconds=1)__format__(...) β Formats self with strftime.isocalendar(...) β Return a named tuple containing ISO year, week number, and weekday.isoweekday(...) β Return the day of the week represented by the date. Monday == 1 ... Sunday == 7strftime(...) β format -> strftime() style string.toordinal(...) β Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.weekday(...) β Return the day of the week represented by the date. Monday == 0 ... Sunday == 6fromisocalendar(...) β int, int, int -> Construct a date from the ISO year, week number and weekday. This is the inverse of the date.isocalendar() functionfromordinal(...) β int -> date corresponding to a proleptic Gregorian ordinal.today(...) β Current date or datetime: same as self.__class__.fromtimestamp(time.time()).daymonthyeartime([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object
All arguments are optional. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.
__eq__(self, value, /) β Return self==value.__format__(...) β Formats self with strftime.__ge__(self, value, /) β Return self>=value.__getattribute__(self, name, /) β Return getattr(self, name).__gt__(self, value, /) β Return self>value.__hash__(self, /) β Return hash(self).__le__(self, value, /) β Return self<=value.__lt__(self, value, /) β Return self<value.__ne__(self, value, /) β Return self!=value.__reduce__(...) β __reduce__() -> (cls, state)__reduce_ex__(...) β __reduce_ex__(proto) -> (cls, state)__repr__(self, /) β Return repr(self).__str__(self, /) β Return str(self).dst(...) β Return self.tzinfo.dst(self).isoformat(...) β Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. The optional argument timespec specifies the number of additional terms of the time to include. Valid options are 'auto', 'hours', 'minutes', 'seconds', 'milliseconds' and 'microseconds'.replace(...) β Return time with new specified fields.strftime(...) β format -> strftime() style string.tzname(...) β Return self.tzinfo.tzname(self).utcoffset(...) β Return self.tzinfo.utcoffset(self).fromisoformat(...) β string -> time from time.isoformat() output__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.foldhourmicrosecondminutesecondtzinfomax = datetime.time(23, 59, 59, 999999)min = datetime.time(0, 0)resolution = datetime.timedelta(microseconds=1)Difference between two datetime values.
timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
All arguments are optional and default to 0. Arguments may be integers or floats, and may be positive or negative.
__abs__(self, /) β abs(self)__add__(self, value, /) β Return self+value.__bool__(self, /) β True if self else False__divmod__(self, value, /) β Return divmod(self, value).__eq__(self, value, /) β Return self==value.__floordiv__(self, value, /) β Return self//value.__ge__(self, value, /) β Return self>=value.__getattribute__(self, name, /) β Return getattr(self, name).__gt__(self, value, /) β Return self>value.__hash__(self, /) β Return hash(self).__le__(self, value, /) β Return self<=value.__lt__(self, value, /) β Return self<value.__mod__(self, value, /) β Return self%value.__mul__(self, value, /) β Return self*value.__ne__(self, value, /) β Return self!=value.__neg__(self, /) β -self__pos__(self, /) β +self__radd__(self, value, /) β Return value+self.__rdivmod__(self, value, /) β Return divmod(value, self).__reduce__(...) β __reduce__() -> (cls, state)__repr__(self, /) β Return repr(self).__rfloordiv__(self, value, /) β Return value//self.__rmod__(self, value, /) β Return value%self.__rmul__(self, value, /) β Return value*self.__rsub__(self, value, /) β Return value-self.__rtruediv__(self, value, /) β Return value/self.__str__(self, /) β Return str(self).__sub__(self, value, /) β Return self-value.__truediv__(self, value, /) β Return self/value.total_seconds(...) β Total seconds in the duration.__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.days β Number of days.microseconds β Number of microseconds (>= 0 and less than 1 second).seconds β Number of seconds (>= 0 and less than 1 day).max = datetime.timedelta(days=999999999, seconds=86399, microseconds=9...min = datetime.timedelta(days=-999999999)resolution = datetime.timedelta(microseconds=1)Fixed offset from UTC implementation of tzinfo.
Method resolution order: timezone, tzinfo, builtins.object
__eq__(self, value, /) β Return self==value.__ge__(self, value, /) β Return self>=value.__getinitargs__(...) β pickle support__gt__(self, value, /) β Return self>value.__hash__(self, /) β Return hash(self).__le__(self, value, /) β Return self<=value.__lt__(self, value, /) β Return self<value.__ne__(self, value, /) β Return self!=value.__repr__(self, /) β Return repr(self).__str__(self, /) β Return str(self).dst(...) β Return None.fromutc(...) β datetime in UTC -> datetime in local time.tzname(...) β If name is specified when timezone is created, returns the name. Otherwise returns offset as 'UTC(+|-)HH:MM'.utcoffset(...) β Return fixed offset.__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.max = datetime.timezone(datetime.timedelta(seconds=86340))min = datetime.timezone(datetime.timedelta(days=-1, seconds=60))utc = datetime.timezone.utc__getattribute__(self, name, /) β Return getattr(self, name).__reduce__(...) β -> (cls, state)Abstract base class for time zone info objects.
__getattribute__(self, name, /) β Return getattr(self, name).__reduce__(...) β -> (cls, state)dst(...) β datetime -> DST offset as timedelta positive east of UTC.fromutc(...) β datetime in UTC -> datetime in local time.tzname(...) β datetime -> string name of time zone.utcoffset(...) β datetime -> timedelta showing offset from UTC, negative values indicating West of UTC__new__(*args, **kwargs) β Create and return a new object. See help(type) for accurate signature.MAXYEAR = 9999MINYEAR = 1__all__ = ('date', 'datetime', 'time', 'timedelta', 'timezone', 'tzinf.../usr/lib/python3.10/datetime.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 16:08 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format