Created
June 27, 2014 19:07
-
-
Save bjmc/ce4e518de8fcbca96489 to your computer and use it in GitHub Desktop.
This file contains 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
>>> tz = tzlocal.get_localzone() | |
>>> utc = pytz.timezone("UTC") | |
>>> utc | |
<UTC> | |
>>> import datetime | |
>>> now = datetime.datetime.now() | |
>>> now | |
datetime.datetime(2014, 6, 27, 12, 6, 12, 676354) | |
>>> tz | |
<DstTzInfo 'America/Los_Angeles' LMT-1 day, 16:07:00 STD> | |
>>> tz.localize(now) | |
datetime.datetime(2014, 6, 27, 12, 6, 12, 676354, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>) | |
>>> tz.localize(now).astimezone(utc) | |
datetime.datetime(2014, 6, 27, 19, 6, 12, 676354, tzinfo=<UTC>) | |
>>> in_utc = tz.localize(now).astimezone(utc) | |
>>> back_to_local = in_utc.astimezone(tz) | |
>>> back_to_local | |
datetime.datetime(2014, 6, 27, 12, 6, 12, 676354, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment