Skip to content

Instantly share code, notes, and snippets.

@vortec
Created February 4, 2013 20:31
Show Gist options
  • Select an option

  • Save vortec/4709504 to your computer and use it in GitHub Desktop.

Select an option

Save vortec/4709504 to your computer and use it in GitHub Desktop.
.strftime('%s') is locale-aware
from pytz import timezone
from datetime import datetime
# From http://en.wikipedia.org/wiki/Eastern_Time_Zone
# "Places that use Eastern Standard Time (EST) when observing standard time (autumn/winter)
# are 5 hours behind Coordinated Universal Time (UTC−05:00)."
us = timezone('US/Eastern')
# GMT during the winter is exactly UTC if I'm not mistaken
uk = timezone('Europe/London')
us_time = datetime.now(us)
uk_time = datetime.now(uk)
us_timestamp = int(us_time.strftime('%s'))
uk_timestamp = int(uk_time.strftime('%s'))
diff = (us_timestamp - uk_timestamp) / 60 / 60
print diff ## -5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment