Skip to content

Instantly share code, notes, and snippets.

@tadeck
Created November 7, 2016 17:24
Show Gist options
  • Save tadeck/0d4bc636afc4bdc6a6291ee45bc0aae8 to your computer and use it in GitHub Desktop.
Save tadeck/0d4bc636afc4bdc6a6291ee45bc0aae8 to your computer and use it in GitHub Desktop.
How to convert local time to different UTC time stamps depending on whether there is, or there isn't DST in effect
>>> import pytz
>>> from datetime import datetime
>>> pytz.timezone('US/Mountain').localize(datetime(year=2016, month=11, day=3, hour=12, minute=0)).astimezone(pytz.UTC).isoformat()
'2016-11-03T18:00:00+00:00'
>>> pytz.timezone('US/Mountain').localize(datetime(year=2016, month=11, day=7, hour=12, minute=0)).astimezone(pytz.UTC).isoformat()
'2016-11-07T19:00:00+00:00'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment