0

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?

Julia Ebert
  • 1,583
  • 1
  • 21
  • 39

1 Answers1

1

See if this works:

from django.utils import timezone
timezone.localtime(timezone.now())

This is from the Django docs.

chirinosky
  • 4,438
  • 1
  • 28
  • 39
  • This sets the timezone based on the `TIME_ZONE` in the settings. My goal is to avoid having to change that manually for every use. If I try to use it without the `TIME_ZONE` set, it defaults to `America/Chicago` again – Julia Ebert Sep 11 '14 at 18:49