timezone doesn't change

81 views
Skip to first unread message

mehrad nayeri

unread,
May 8, 2020, 8:28:56 AM5/8/20
to Django users
Hi,
I'm using django 1.11.17 and I've changed TIME_ZONE in settings.py to 'Asia/Tehran' but django.utils.timezone.now() returns UTC time.
How I have to fix it? Why it doesn't work? Does it work on newer release?
Please answer

Andréas Kühne

unread,
May 8, 2020, 9:24:49 AM5/8/20
to django...@googlegroups.com
Hi,

That is actually the expected behaviour - django.utils.timezone.now() should always return a UTC time.

You should always communicate in the backend with UTC time - saving everything to the database and so on - it should always be in UTC. 

When you want to present a time in a template or to the user you need to do this according to the documentation: 

There is a lot of information there regarding handling timezones - but now() will always return a UTC (if timezone support is on :))

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27fd5fd2-b6dc-4ed2-997b-3a07f061427b%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages