Retrieve timezone aware DateTimeField in Django Retrieve timezone aware DateTimeField in Django django django

Retrieve timezone aware DateTimeField in Django


If you have USE_TZ = True in your settings, Django stores all the datetime objects in the database as UTC and convert them to your TIME_ZONE=XYZ from settings.py on the fly when rendering in the templates.

That is why, when retrieved from the database, datetime object is timezone aware but it has UTC as its timezone (hence +00:00 in 2016-06-18 08:18:00+00:00). As, you are converting the time to str yourself (and not rendering in the template) so Django does not convert it to your TIME_ZONE setting. You need to convert it yourself to your desired TimeZone.

If you want to convert it to the TimeZone from your TIME_ZONE setting, you can do

from django.utils import timezoneto_tz = timezone.get_default_timezone()print return_event.return_time.astimezone(to_tz).strftime("%H:%M")