Skip to content

Instantly share code, notes, and snippets.

@jbfuzier
Created February 13, 2017 17:32
Show Gist options
  • Save jbfuzier/7ee6ecdb716f8bb69c8555b437abef08 to your computer and use it in GitHub Desktop.
Save jbfuzier/7ee6ecdb716f8bb69c8555b437abef08 to your computer and use it in GitHub Desktop.
Python Timezone conversion
from dateutil import tz
tzone = tz.gettz('Europe/Paris')
utc = tz.gettz('UTC')
# Make datetime object timezone aware
datetime_local = datetime_local.replace(tzinfo=tzone)
# Do the timezone change
date_utc = datetime_local.astimezone(utc)
# Epoch timestamp to timezone aware datetime
datetime.datetime.utcfromtimestamp(time).replace(tzinfo=utc)
@jbfuzier
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment