Created
December 13, 2011 23:24
-
-
Save mapio/1474444 to your computer and use it in GitHub Desktop.
Rebase for Formatting
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
from datetime import datetime | |
from pytz import utc, timezone | |
# My local time in Italy is now midnight | |
local_time = datetime.now() | |
print local_time.strftime( '%H' ), local_time.hour # outputs "00 0" | |
# Following http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/ | |
# take that UTC datetime object | |
utcnow = datetime.utcnow() | |
# attach the UTC timezone information | |
utcnow_with_tz = utc.localize( utcnow ) | |
# look up the user's timezone | |
italy = timezone( 'Europe/Rome' ) | |
# rebase to local time and format. | |
rebased = utcnow_with_tz.astimezone( italy ) # do you mean this with "rebase"? | |
print rebased.strftime( '%H' ), rebased.hour # outputs "00 0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is ok, according to the blog author himself https://twitter.com/#!/mitsuhiko/status/147339524731711489