Christopher Pisz
Christopher Pisz

Reputation: 4000

Get Timezone to take effect

I am going through the Django tutorial. I thought the TIME_ZONE in settings.py was of form 'UTC-5', but it isn't. I replaced it with 'America/Chicago'

However, when I do:

python manage.py shell

from django.utils import timezone
timezone.now()

I get 'UTC' How do I get the timezone to take effect?

Upvotes: 0

Views: 33

Answers (1)

dfundako
dfundako

Reputation: 8314

It can be confusing. If you run the code below, you will see that it is set, but it won't output as you expect:

from django.utils import timezone
timezone.get_current_timezone() # Should be 'America/Chicago'
timezone.now() # should show UTC

If you want it to output in the shell with your set timezone, use timezone.localtime()

from django.utils import timezone
timezone.localtime()

Upvotes: 1

Related Questions