Standard library conversions

Most classes have an equivalent in the Python standard library. Use the to_stdlib() method to convert to the standard library equivalent, or pass the standard library object directly to the constructor:

>>> from datetime import *
>>> from whenever import *
>>> py_dt = datetime(2025, 4, 19, 15, 30, tzinfo=timezone.utc)
>>> instant = Instant(py_dt)
>>> instant.to_stdlib()
datetime.datetime(2025, 4, 19, 15, 30, tzinfo=datetime.timezone.utc)

Note

  • There are some exceptions where the conversion is not exact; see the individual method documentation for details.

  • Converting to the standard library is not always lossless. Nanoseconds will be truncated to microseconds.

  • The constructor also accepts subclasses, so you can also ingest types from pendulum and arrow libraries.

There are no Python equivalents for the following classes: