Converting time from GMT to another timezone
Stuart Bishop
zen at shangri-la.dropbear.id.au
Sat Mar 22 19:18:04 EST 2003
On Saturday, March 22, 2003, at 10:24 PM, Andrew Markebo wrote:
> / Jp Calderone <exarkun at intarweb.us> wrote:
> | [...]
> | import time
> | now_EST = time.time() - 18000
> | print time.asctime(time.gmtime(now_EST))
>
> Just being interested, these 18000, is it possible to find out how
> much that is? I mean.. make a general python code that can show me the
> time difference between EST and CET?
>
> Or is it something I as developer has to look up and hardcode into my
> code?
Manipulating the TZ environment variable may work, depending on
your OS:
>>> import os
>>> os.environ['TZ'] = 'US/Eastern'
>>> print time.asctime(time.localtime(time.time()))
Sat Mar 22 19:06:34 2003
>>> os.environ['TZ'] = 'UTC'
>>> print time.asctime(time.localtime(time.time()))
Sun Mar 23 00:06:57 2003
>>> os.environ['TZ'] = 'US/Eastern'
>>> now = time.time()
>>> now - time.mktime(time.gmtime(now))
-17999.518725991249
Note that if you take this approach, variables exposed by the time
module
(time.timezone, time.altzone etc.) will no longer reflect the actual
output of the functions.
Unfortunatly, there is no way to do timezone conversion stuff under Unix
that doesn't suck. Work is underway to provide these sucky ways in
Python 2.3.
Rumour has it that Windows provides a richer interface for timezone
stuff,
but it appears to be a secret.
--
Stuart Bishop <zen at shangri-la.dropbear.id.au>
http://shangri-la.dropbear.id.au/
More information about the Python-list
mailing list