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())
# UTC time now with timezone info
print(datetime.now().astimezone(tz=timezone.utc).replace(microsecond=0).isoformat())
Local Time¶
# Local time now with timezone info
print(datetime.now().astimezone().replace(microsecond=0).isoformat())