Created
March 21, 2010 05:08
-
-
Save cosmin/339106 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
# tzdate - helper functions for using timezones from dateutil. utcnow and localnow. | |
import datetime | |
from dateutil import tz | |
UTC_TZ = tz.gettz('UTC') | |
LOCAL_TZ = tz.gettz() | |
def utcnow(): | |
return datetime.datetime.now(UTC_TZ) | |
def localnow(): | |
return datetime.datetime.now(LOCAL_TZ) | |
def naive_to_tz(naive_date, target_tz): | |
b = list(naive_date.timetuple())[:-2] | |
b.append(LOCAL_TZ) | |
return datetime.datetime(*b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment