Converting time from GMT to another timezone

Peter Hansen peter at engcorp.com
Sat Mar 22 09:31:56 EST 2003


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?

Yes, sort of, and no.  I found this in rfc822.py.  It's not in any
way a complete solution, but it tells a lot.

# The timezone table does not include the military time zones defined
# in RFC822, other than Z.  According to RFC1123, the description in
# RFC822 gets the signs wrong, so we can't rely on any such time
# zones.  RFC1123 recommends that numeric timezone indicators be used
# instead of timezone names.

_timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
              'AST': -400, 'ADT': -300,  # Atlantic (used in Canada)
              'EST': -500, 'EDT': -400,  # Eastern
              'CST': -600, 'CDT': -500,  # Central
              'MST': -700, 'MDT': -600,  # Mountain
              'PST': -800, 'PDT': -700   # Pacific
              }

-Peter




More information about the Python-list mailing list