How to use timezone.now() in django with activate timezone?
I am using Django 3.2 and changed my setting.py
as
TIME_ZONE = 'Asia/Calcutta'
USE_I18N = True
USE_L10N = True
USE_TZ = True
and try to use timezone.now()
It gives me the UTC time when I print it from my view.py
It worked well for DateTimeField
in models when I store some data into it. I also activate the timezone
from django.utils.timezone import activate
activate(settings.TIME_ZONE)
I don't know why it works for models but not for view. Can anybody explain how to use timezone in django.
datetime.datetime.now() # 2022-08-29 02:03:44.941847
timezone.localtime(timezone.now()) # 2022-08-29 02:03:44.941847+05:30
timezone.now() # 2022-08-28 20:33:44.941847+00:00
timezone.get_current_timezone() # Asia/Kolkata