Comment 3 for bug 879480

Revision history for this message
Alain Spineux (alain-spineux) wrote :

I get naive datetime from SqlAlchemy in UTC and want to display it in the user 's local timezone, I used this

pytz.timezone(USER_LOCAL_TIMEZONE).fromutc(DATETIME_FROM_SQLALCHEMY)

If i'm wrong please tell me !

datetime.astimezone() works, but with some more code because it doesn't expect a naive datetime

>>> datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/Brussels'))
datetime.datetime(2011, 11, 4, 10, 36, 51, 416512, tzinfo=<DstTzInfo 'Europe/Brussels' CET+1:00:00 STD>)
>>> datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone('utc'))
datetime.datetime(2011, 11, 4, 9, 37, 5, 320588, tzinfo=<UTC>)

Thanks