Django 1.4 and time zones

The django docs states that they can always store datetime objects in TIME_ZONE provided in preferences.

I wanted to ask, is this enough to bring time-aware objects to time, or do we need to convert them to TIME_ZONE setting? those. if my TIME_ZONE = "America / Los_Angeles" and USE_TZ = "True" and I try to store an object corresponding to the timezone that is in "UTC", does it work? That is, will django convert this "UTC" timezone object to "America / Los_Angeles" before storing it in the db?

+3


source to share


1 answer


I believe that when USE_TZ = True

django will save everything to the DB in UTC. Every DateTime object must be timezone aware in order to save. When django fetches the datetime from the database, it automatically changes it from UTC to the timezone specified TIME_ZONE

in the settings.

So, to answer your question, if you have a timezone-related date and time in UTC (say 19:00) and you save it, it will store it in the DB as 19:00. When you fetch it, django will make it TZ in America / Los_angelos, so the datetime will be 12:00.



You can also override the current time zone setting by selecting in preferences by calling

from django.utils import timezone
timezone.activate('US/Central')

      

+7


source







All Articles