1

This is my settings.py:

TIME_ZONE = 'America/Toronto'

USE_I18N = True

USE_L10N = True

USE_TZ = True

Before, it used to be TIME_ZONE = 'UTC' but I just changed it right now. I restarted the development server after changing it and created a post but the date and time of when the post was created is still now according to the Toronto timezone (it still follows the previous timezone it was in). My model is using the default DateTimeField:

createdAt = models.DateTimeField(auto_now_add=True, blank=True)

Is there anything else which needs to be changed in order for the timezone changes to take effect? I just tried doing

python manage.py makemigrations
python manage.py migrate

but it said no changes detected (as expected).

Edit: Note that I am also using DRF and serializers to serialize the posts. I'm not sure if that makes a difference though (do I need to change any DRF settings?).

Serjik
  • 10,543
  • 8
  • 61
  • 70
SilentDev
  • 20,997
  • 28
  • 111
  • 214
  • 1
    try this USE_TZ = False – Serjik Nov 07 '15 at 04:10
  • @Serjik That worked. Thanks! You can put it down as the answer and I will check it off. On a side note, why exactly Did it work? Shouldn't `USE_TZ` be `True` so that Django can use the Time Zone which I set it to? – SilentDev Nov 07 '15 at 04:18

1 Answers1

2

When support for time zones is enabled, Django stores datetime information in UTC in the database, uses time-zone-aware datetime objects internally, and translates them to the end user’s time zone in templates and forms. django docs

so try this

USE_TZ = False
Serjik
  • 10,543
  • 8
  • 61
  • 70