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