Is there no inversion of gmtime()?

Dparsavand dparsavand at aol.com
Wed Jun 21 15:48:02 EDT 2000


Jürgen Hermann wrote:
> There are actually two such functions, time.mktime() and 
> rfc822.mktime_tz(). Now read the docs. :)

I did read the time module documentation before posting - the function
time.mktime is an inverse of time.localtime and thus at first, I did not think
of using it. So, in otherwords:

Set sec to an integer >= 0 
Import the time module
(mktime(localtime(sec))) correctly returns sec (as a float)
Is there a function f such that (f(gmtime(sec))) returns sec?

There is no function f explicitly listed in the time module (nor rfc822), but I
didn't see that it is easy to construct one with use of the timezone variable.
(mktime(gmtime(sec)) - timezone) returns sec correctly in all cases I've tried
so far.

Martin P Holland wrote:
> There was a thread about this in this newsgroup around 05/03/1999 and
> G. van Rossum posted a readable solution (which does what you'd expect)
> which I use in my ftpupdater app

I only briefly looked at this code, but I'll probably just use the timezone
offset. 

Thanks, Dara



More information about the Python-list mailing list