datetimeΒΆ

Show different times: UTC, local time, etc

>>> # Build at
>>> import datetime
>>> datetime.datetime.utcnow()  # UTC
datetime.datetime(2022, 5, 10, 16, 10, 41, 619715)
>>> datetime.datetime.now()  # local time
datetime.datetime(2022, 5, 10, 16, 10, 41, 619777)
>>> # Build at with timezones
>>> import datetime
>>> import pytz
>>> from pytz import timezone
>>> utcnow = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
>>> utcnow.astimezone(timezone('Europe/Madrid'))  # Madrid, Spain
datetime.datetime(2022, 5, 10, 18, 10, 41, 655290, tzinfo=<DstTzInfo 'Europe/Madrid' CEST+2:00:00 DST>)
>>> utcnow.astimezone(timezone('America/Los_Angeles'))  # Los Angeles, USA
datetime.datetime(2022, 5, 10, 9, 10, 41, 655290, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>)
>>> utcnow.astimezone(timezone('America/Guayaquil'))  # Guayaquil, Ecuador
datetime.datetime(2022, 5, 10, 11, 10, 41, 655290, tzinfo=<DstTzInfo 'America/Guayaquil' -05-1 day, 19:00:00 STD>)