UTC equivalent of time.mktime() ?

Graham Ashton gashton at cmedltd.com
Thu Apr 18 05:14:03 EDT 2002


On Wed, 2002-04-17 at 18:51, Donn Cave wrote:
> I have not been following, so pardon me if this has already been
> suggested, but on a platform where you have 2.0 or later and strptime,
> this might do that:
> 
>   lt = time.mktime(time.strptime(sys.argv[1], '%d %b %Y'))
>   utoffset = time.mktime(time.gmtime(lt)) - lt
>   print lt - utoffset

Thanks for that.

I was using strptime() and mktime() to get seconds since the epoch in
localtime. I was trying to work out if I could do anything simpler than
this (in which two of the "-" signs should be "+" signs):

>>> def local2utc(secs):
...     if time.daylight:
...         return secs - time.timezone - time.altzone
...     else:
...         return secs - time.timezone

to get the seconds since the epoch into UTC. It's looking as though the
answer (in general) is "no".

-- 
Graham Ashton






More information about the Python-list mailing list