datetime

The Python standard-library module and type that represent a date and time of day.

In more detail

datetime objects can be compared, subtracted to give a timedelta, and used as dict keys. A datetime can be naive or carry a time zone.

Examples

Python randomises datetime hashes per process, as it does for str and bytes.
In this course: datetime.now(timezone.utc) reads the machine's clock, which makes any code that calls it a moving input. Passing a fixed datetime in as an argument lets a test state the exact instant and boundary it means.

Related terms

Taught in

References