Problems when working with different timezones

ocgstyles at gmail.com ocgstyles at gmail.com
Tue Sep 2 19:40:07 CEST 2008


Here's some Python code executed on Red Hat 3.4 web server located in
Mountain time (MDT).  You'll notice that the time after setting the
timezone to Eastern time (EST), the time is incorrectly 6 hours ahead,
when it should only be 3.

Python 2.5 (r25:51908, Mar 23 2007, 14:22:20)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime, os
>>> datetime.datetime.today()
datetime.datetime(2008, 9, 2, 11, 25, 35, 39856)
>>> os.environ['TZ']='America/New_York'
>>> datetime.datetime.today()
datetime.datetime(2008, 9, 2, 17, 26, 0, 703537)

Here's the same thing executed on an Ubuntu box in EST.  I alter the
timezone to a MDT and it works as one would expect.

Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime, os
>>> datetime.datetime.today()
datetime.datetime(2008, 9, 2, 13, 11, 6, 438123)
>>> os.environ['TZ'] = 'America/Denver'
>>> datetime.datetime.today()
datetime.datetime(2008, 9, 2, 11, 11, 21, 43602)

What could be the reason for this failing on Red Hat?

Keith



More information about the Python-list mailing list