Converting time from GMT to another timezone

Peter Hansen peter at engcorp.com
Fri Mar 21 17:31:38 EST 2003


Ehab Teima wrote:
> 
> I tried all possible ways to convert time from GMT to another timezone
> but I could not. In particular, I'm interested in converting the
> machine's clock that has the timezone defined as GMT to eastern
> standard time. Is there any way to do that, on Windows?

What I'm wondering is what you want, other than to take time.time()
and add 5 hours to it...

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
>>> import time
>>> now = time.time()
>>> now
1048285657.33
>>> time.gmtime(now)
(2003, 3, 21, 22, 27, 37, 4, 80, 0)
>>> time.localtime(now)
(2003, 3, 21, 17, 27, 37, 4, 80, 0)
>>> print time.gmtime.__doc__
gmtime(seconds) -> tuple

Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. GMT).
>>> adjusted = now + 60*60*5
>>> time.localtime(adjusted)
(2003, 3, 21, 22, 27, 37, 4, 80, 0)

In effect, adding 60*60*5 lets time.localtime() produce a result which
corresponds to the result time.gmtime() produces with the unadjusted
value.

Really, it's unclear what you are trying to do.

-Peter




More information about the Python-list mailing list