Skip to content

Instantly share code, notes, and snippets.

@mapio
Created December 13, 2011 23:24
Show Gist options
  • Save mapio/1474444 to your computer and use it in GitHub Desktop.
Save mapio/1474444 to your computer and use it in GitHub Desktop.
Rebase for Formatting
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"
@mapio
Copy link
Author

mapio commented Dec 19, 2011

This is ok, according to the blog author himself https://twitter.com/#!/mitsuhiko/status/147339524731711489

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment