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

Source

now()

Returns a datetime that represents the current point in time. Exactly what’s returned depends on the value of USE_TZ:

If USE_TZ is False, this will be a naive datetime (i.e. a datetime without an associated timezone) that represents the current time in the system’s local timezone.

If USE_TZ is True, this will be an aware datetime representing the current time in UTC. Note that now() will always return times in UTC regardless of the value of TIME_ZONE; you can use localtime() to get the time in the current time zone.

Back to Top