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.

Revisions

  1. jbfuzier created this gist Feb 13, 2017.
    13 changes: 13 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@

    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)