datetimeΒΆ

Show different times: UTC, local time, etc

>>> # Build at
>>> import datetime
>>> datetime.datetime.utcnow()  # UTC
datetime.datetime(2020, 3, 10, 22, 46, 55, 929448)
>>> datetime.datetime.now()  # local time
datetime.datetime(2020, 3, 10, 22, 46, 55, 929513)
>>> # 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(2020, 3, 10, 23, 46, 56, 53778, tzinfo=<DstTzInfo 'Europe/Madrid' CET+1:00:00 STD>)
>>> utcnow.astimezone(timezone('America/Los_Angeles'))  # Los Angeles, USA
datetime.datetime(2020, 3, 10, 15, 46, 56, 53778, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>)
>>> utcnow.astimezone(timezone('America/Guayaquil'))  # Guayaquil, Ecuador
datetime.datetime(2020, 3, 10, 17, 46, 56, 53778, tzinfo=<DstTzInfo 'America/Guayaquil' -05-1 day, 19:00:00 STD>)