Much to my surprise, it does appear too.
web81:~/webapps/dominicrodger2/dominicrodger$ python2.5 manage.py shell
Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import settings
>>> settings.TIME_ZONE
'Europe/London'
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2009, 10, 15, 6, 29, 58, 85662)
>>> exit()
web81:~/webapps/dominicrodger2/dominicrodger$ date
Thu Oct 15 00:31:10 CDT 2009
And yes, I did get distracted whilst writing this answer :-)
I use the TIME_ZONE
setting so that my automatically added timestamps on object creation (using auto_now_add
, which I believe is soon to be deprecated) show creation times in the timezone I set.
If you want to convert those times into the timezones of your website visitors, you'll need to do a bit more work, as per the example you gave. If you want to do lots of timezone conversion to display times in your website visitors' timezones, then I'd strongly advise you to set your TIME_ZONE
settings to store times in UTC, because it'll make your life easier in the long run (you can just use UTC-offsets, rather than having to worry about daylight savings).
If you're interested, I believe the timezone is set from the TIME_ZONE
setting here.
Edit, per your comment that it doesn't work on Windows, this is because of the following in the Django source:
if hasattr(time, 'tzset'):
# Move the time zone info into os.environ. See ticket #2315 for why
# we don't do this unconditionally (breaks Windows).
os.environ['TZ'] = self.TIME_ZONE
time.tzset()
Windows:
C:\Documents and Settings\drodger>python
ActivePython 2.6.1.1 (ActiveState Software Inc.) based on
Python 2.6.1 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> hasattr(time, 'tzset')
False
Linux:
web81:~$ python2.5
Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> hasattr(time, 'tzset')
True