# pydoc > datetime

---
type: CommandReference
command: datetime
mode: pydoc
section: 
source: pydoc3
---

## Quick Reference
- `datetime.date(year, month, day)` — create a date object
- `datetime.datetime.now()` — current local datetime
- `datetime.datetime.utcnow()` — current UTC datetime
- `datetime.datetime.strptime(string, format)` — parse string to datetime
- `datetime.datetime.combine(date, time)` — combine date and time
- `datetime.timedelta(days=..., seconds=...)` — time difference
- `datetime.timezone.utc` — UTC timezone instance
- `datetime.timedelta.total_seconds()` — total seconds in duration

## Name
Fast implementation of the datetime type.

## Synopsis
python
import datetime
# or from datetime import date, datetime, time, timedelta, timezone, tzinfo
## Classes

### class date
Constructs a date object: `date(year, month, day)`.

**Methods:**
- `ctime()` — Return ctime() style string.
- `isocalendar()` — Return named tuple (ISO year, week number, weekday).
- `isoformat()` — Return string in ISO 8601 format, `YYYY-MM-DD`.
- `isoweekday()` — Return day of week (Monday=1, Sunday=7).
- `replace(...)` — Return date with new specified fields.
- `strftime(format)` — Format using strftime style string.
- `timetuple()` — Return time tuple compatible with `time.localtime()`.
- `toordinal()` — Return proleptic Gregorian ordinal (Jan 1 year 1 = day 1).
- `weekday()` — Return day of week (Monday=0, Sunday=6).

**Class methods:**
- `fromisocalendar(year, week, weekday)` — Construct date from ISO year, week, weekday.
- `fromisoformat(string)` — Construct date from ISO format string.
- `fromordinal(ordinal)` — Construct date from ordinal.
- `fromtimestamp(timestamp)` — Create date from POSIX timestamp (local time).
- `today()` — Current date (same as `fromtimestamp(time.time())`).

**Data descriptors:** `day`, `month`, `year`

**Attributes:** `max = date(9999,12,31)`, `min = date(1,1,1)`, `resolution = timedelta(days=1)`

### class datetime
Constructor: `datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])`. The year, month, day are required. tzinfo may be None or a tzinfo instance.

**Methods (own):**
- `astimezone(tz)` — Convert to local time in new timezone tz.
- `ctime()` — ctime() style string.
- `date()` — Return date object with same year, month, day.
- `dst()` — Return `self.tzinfo.dst(self)`.
- `isoformat(sep='T', timespec='auto')` — ISO 8601 string: `YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]`. timespec options: 'auto', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds'.
- `replace(...)` — Return datetime with new specified fields.
- `time()` — Return time object with same time and tzinfo=None.
- `timestamp()` — Return POSIX timestamp as float.
- `timetuple()` — 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()` — UTC time tuple.

**Class methods:**
- `combine(date, time)` — Combine date and time into datetime.
- `fromisoformat(string)` — Construct datetime from ISO format string.
- `fromtimestamp(timestamp[, tz])` — Construct datetime from POSIX timestamp, optionally with timezone.
- `now(tz=None)` — Return current local datetime; if tz given, local to that timezone.
- `strptime(string, format)` — Parse string with format (like `time.strptime()`).
- `utcfromtimestamp(timestamp)` — Construct naive UTC datetime from POSIX timestamp.
- `utcnow()` — Return current UTC datetime.

**Data descriptors (own):** `fold`, `hour`, `microsecond`, `minute`, `second`, `tzinfo`

**Inherited from date:** `day`, `month`, `year`, plus methods: `ctime()`, `isocalendar()`, `isoweekday()`, `strftime()`, `toordinal()`, `weekday()`, `fromisocalendar()`, `fromordinal()`, `today()`, `__format__()`.

**Attributes:** `max = datetime(9999,12,31,23,59,59,999999)`, `min = datetime(1,1,1)`, `resolution = timedelta(microseconds=1)`

### class time
Constructor: `time([hour[, minute[, second[, microsecond[, tzinfo]]]]])`. All arguments optional.

**Methods:**
- `dst()` — Return `self.tzinfo.dst(self)`.
- `isoformat(timespec='auto')` — ISO 8601 string: `[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]`.
- `replace(...)` — Return time with new specified fields.
- `strftime(format)` — Format using strftime.
- `tzname()` — Return `self.tzinfo.tzname(self)`.
- `utcoffset()` — Return `self.tzinfo.utcoffset(self)`.

**Class methods:**
- `fromisoformat(string)` — Construct time from ISO format string.

**Data descriptors:** `fold`, `hour`, `microsecond`, `minute`, `second`, `tzinfo`

**Attributes:** `max = time(23,59,59,999999)`, `min = time(0,0)`, `resolution = timedelta(microseconds=1)`

### class timedelta
Constructor: `timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)`. Arguments can be int or float, positive or negative.

**Methods:**
- `total_seconds()` — Total seconds in the duration.

**Supported operations:** Addition, subtraction, multiplication, division, floor division, modulo, negation, absolute value, comparison, hashing.

**Data descriptors:** `days` (Number of days), `seconds` (0–86399), `microseconds` (0–999999)

**Attributes:** `max = timedelta(days=999999999, seconds=86399, microseconds=999999)`, `min = timedelta(days=-999999999)`, `resolution = timedelta(microseconds=1)`

### class tzinfo
Abstract base class for time zone info objects.

**Methods:**
- `dst(datetime)` — Return DST offset as timedelta (positive east of UTC).
- `fromutc(datetime)` — Convert UTC datetime to local time.
- `tzname(datetime)` — Return string name of time zone.
- `utcoffset(datetime)` — Return timedelta offset from UTC (negative west of UTC).

### class timezone
Fixed offset from UTC implementation of tzinfo.

**Constructor:** `timezone(offset, name=None)` — offset is a timedelta, optional name string.

**Methods:**
- `dst(datetime)` — Return None.
- `fromutc(datetime)` — Convert UTC datetime to local time.
- `tzname(datetime)` — If name specified, returns name; otherwise returns offset as `'UTC(+|-)HH:MM'`.
- `utcoffset(datetime)` — Return fixed offset.

**Attributes:** `utc = timezone.utc` (UTC timezone instance), `max = timezone(timedelta(hours=23, minutes=59))`, `min = timezone(timedelta(hours=-23, minutes=59))`

## Data
- `MAXYEAR = 9999`
- `MINYEAR = 1`
- `__all__ = ('date', 'datetime', 'time', 'timedelta', 'timezone', 'tzinfo')`

## See Also
- [Python datetime module documentation](https://docs.python.org/3.10/library/datetime.html)
- `time` module (standard library)
- `calendar` module