Time zones

David Bolen db3l at fitlinxx.com
Wed Dec 1 17:45:51 EST 2004


Timothy Hume <t.hume at bom.gov.au> writes:

> I want to ensure that all my time calculations are done in UTC. This is 
> easy with Python on UNIX machines. I simply set the TZ environment 
> variable to "UTC", and it ensures that the time functions use UTC. 
> 
> My question is, how do I get similar functionality using Python on 
> Windows?

If you're just talking about time module functions, I think you should
be able to do the same thing.  The time functions are overlays for the
C library versions which do use tzset() and look at the TZ environment
variable as under Unix.

> py24
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.tzname
('Eastern Standard Time', 'Eastern Daylight Time')
>>> print time.ctime()
Wed Dec 01 17:42:08 2004

> TZ=UTC py24
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.tzname
('UTC', '')
>>> print time.ctime()
Wed Dec 01 22:42:21 2004


(I've used 2.4 here, but the same results work back until 1.5.2)

-- David



More information about the Python-list mailing list