Created
August 21, 2012 17:33
-
-
Save adeel/3417600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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