To my great surprise, this is similar.
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 really got distracted by writing this answer :-)
I use the TIME_ZONE parameter so that automatically added timestamps when creating an object (using auto_now_add , which, it seems to me, will soon become obsolete) show the creation time in the time zone you set.
If you want to convert these times into time zones for visitors to your site, you will need to do a little more work, as shown in the example that you gave. If you want to make a lot of time to display the time on the clock of your time on the website, I highly recommend that you set your TIME_ZONE settings for storing time in UTC, because it will simplify your life in the long run (you can simply use UTC offsets instead of worrying about summer savings).
If you're interested, I believe the time zone is set from the TIME_ZONE parameter here .
Change, for your comment, that it does not 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()
Window:
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