Why do i keep getting UTC time zone even when Django settings is configured differently
I'm not sure why the datetime response is always one hour behind (UTC)
Django settings configuration
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Africa/Lagos"
USE_I18N = True
USE_L10N = True
USE_TZ = True
DATE_FORMAT = "F j, Y"
SITE_ID = 1
from django.utils import timezone
timezone.now()
response:
datetime.datetime(2022, 7, 23, 13, 58, 6, 739601, tzinfo=<UTC>)
You can see that the time zone info is UTC
Try: 1.download latest pytz file (pytz-2019.3.tar.gz) from https://pypi.org/simple/pytz/
2.copy and extract it to site_packages directory on your project
3.in cmd go to the exracted folder and run "python setup.py install"
4.TIME_ZONE = 'Etc/GMT+3' or country name
It needs to be done like this:
LANGUAGE_CODE = "en-us"
TIME_ZONE = "Africa/Lagos"
USE_I18N = True
USE_L10N = False
USE_TZ = False
now()Returns a datetime that represents the current point in time. Exactly what’s returned depends on the value of
USE_TZ:If
USE_TZis False, this will be a naivedatetime(i.e. a datetime without an associated timezone) that represents the current time in the system’s local timezone.If
USE_TZis True, this will be an awaredatetimerepresenting the current time in UTC. Note thatnow()will always return times in UTC regardless of the value ofTIME_ZONE; you can uselocaltime()to get the time in the current time zone.