Mailing List Archive

timelocal
I noticed that there doesn't currently seem to be a
function that takes a tuple of date information (like
that returned by localtime()) and turns it into a
Unix time -- effectively, the reverse operation to
localtime() or gmtime().

It's a very useful operation to have when working
with dates and times. Perl has it in the timelocal.pl
script and i was thinking of stealing the logic in it
to add a similar function to Python.

So, before i go reinvent the wheel -- have i missed the
fact that we already have this function? Would anyone
care if it was added?

Thanks for your thoughts...


-- ?!ng
Re: timelocal [ In reply to ]
Ka-Ping Yee writes:
> So, before i go reinvent the wheel -- have i missed the
> fact that we already have this function? Would anyone
> care if it was added?

I'd love to see this added!


-Fred

--
Fred L. Drake, Jr. <fdrake at acm.org>
Corporation for National Research Initiatives
Re: timelocal [ In reply to ]
> I noticed that there doesn't currently seem to be a
> function that takes a tuple of date information (like
> that returned by localtime()) and turns it into a
> Unix time -- effectively, the reverse operation to
> localtime() or gmtime().

To go from a local time tuple to Unix time, there's time.mktime().
To go from a gm time tuple to Unix time, there's calendar.timegm().
(The latter only exists in the CVS version.)

--Guido van Rossum (home page: http://www.python.org/~guido/)