Skip to content

Instantly share code, notes, and snippets.

@adeel
Created August 21, 2012 17:33
Show Gist options
  • Save adeel/3417600 to your computer and use it in GitHub Desktop.
Save adeel/3417600 to your computer and use it in GitHub Desktop.
import pytz
def localize(date, time_zone):
"Convert the date to the local time zone (from UTC)."
return date.replace(second=0, microsecond=0,
tzinfo=pytz.utc).astimezone(pytz.timezone(time_zone))
def to_utc(date, time_zone):
"Change a datetime corresponding to the time_zone to UTC time."
return pytz.timezone(time_zone).localize(date.replace(
second=0, microsecond=0)).astimezone(pytz.utc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment