Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created April 12, 2019 11:08
Show Gist options
  • Save Clivern/b4a8ea455c9f1b970daa74e34ae4c97c to your computer and use it in GitHub Desktop.
Save Clivern/b4a8ea455c9f1b970daa74e34ae4c97c to your computer and use it in GitHub Desktop.
Change Python Datetime to Timezone Aware
import datetime
import pytz
unaware = datetime.datetime(2019, 8, 15, 8, 15, 12, 0)
aware = datetime.datetime(2019, 8, 15, 8, 15, 12, 0, pytz.UTC)
now_aware = unaware.replace(tzinfo=pytz.UTC)
assert aware == now_aware
print(aware)
print(now_aware)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment