Reputation: 1623
I am trying to use times in an intranet system, which will have independent servers/systems run in different time zones. Because time zones are a pain and my use of times is fairly simple (showing the user when they last modified a file, for example), I thought I would just use naive times. However, the naive timezone Django comes up with is incorrect.
Settings.py:
# No TIME_ZONE specified because I want it to use whatever the system time is
USE_L10N = False
USE_TZ = False
From a Django console, I run os.getenv('TZ')
and it returns 'America/Chicago'
, though the computer is set to America/New_York
. (If I call date
in a command line, it shows that I am in EDT.) Therefore, when I call timezone.now()
or datetime.datetime.now()
the result is an hour early. (When I call timezone.is_aware()
on either of these, it does return False
.)
My question: why is this time zone incorrect relative to the system time, and is there a way I can fix it?
Upvotes: 0
Views: 225
Reputation: 4538
See if this works:
from django.utils import timezone
timezone.localtime(timezone.now())
This is from the Django docs.
Upvotes: 1