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:
- Make wrapper functions/methods for datetime.datetime.now() and time.time(). This can break things if you’re not careful.
- Run django on a UNIX operating system
- Virtually run Django on a UNIX using a free VMware with a Virtual Appliance that has Django and many Python modules and more…
- Fix the bug
- September 28th, 2006 by Gerald Kaszuba
- Posted in Programming, python |
- 2 Comments »







