Skip to content

ISO 8601 Timestamp in Python

ISO 8601 Data elements and interchange formats – Information interchange – Representation of dates and times is an international standard covering the exchange of date- and time-related data. It was issued by the International Organization for Standardization (ISO) and was first published in 1988.

from datetime import datetime, timezone, tzinfo

UTC Time

# UTC time now
print(datetime.utcnow().replace(microsecond=0).isoformat())
2020-05-12T16:16:06

# UTC time now with timezone info
print(datetime.now().astimezone(tz=timezone.utc).replace(microsecond=0).isoformat())
2020-05-12T16:16:06+00:00

Local Time

# Local time now with timezone info
print(datetime.now().astimezone().replace(microsecond=0).isoformat())
2020-05-12T12:16:06-04:00

Open In Colab