Skip to content

Instantly share code, notes, and snippets.

@shervinafshar
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shervinafshar/641ac6a5df2f2f5749c0 to your computer and use it in GitHub Desktop.
Save shervinafshar/641ac6a5df2f2f5749c0 to your computer and use it in GitHub Desktop.
Using `pytz` for conversation of time and date into other timezones.
import pytz, datetime, calendar
#import dateutil
d1 = datetime.datetime(2013, 4, 20, 7, 50, tzinfo=pytz.timezone('US/Pacific'))
d2 = datetime.datetime(2013, 4, 20, 9, 40, tzinfo=pytz.timezone('US/Pacific'))
d1Utc = d1.astimezone(pytz.timezone('UTC'))
d1UtcTs = calendar.timegm(d1.utctimetuple())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment