Django time zone problem

This is a Django bug specific to Windows and it took me half a day to figure out because I trusted the datetime module! Basically if you set your TIME_ZONE in the settings.py file like so:

TIME_ZONE = 'Australia/Sydney'

The datetime and time modules will always return the UTC date.

The strange thing is that if you use “python manage.py shell” you get the bug but if you just use “python” you don’t get the bug.

Correct time:

c:\project>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2006, 9, 28, 12, 11, 38, 109000)

Django time:

c:\project>python manage.py shell --plain
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2006, 9, 28, 3, 12, 16, 468000)

Possible solutions:

2 thoughts on “Django time zone problem”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>