timegm() equivalent function in Python?

Dietmar Lang dietmar at nospam.wohnheim.fh-wedel.de
Wed Sep 26 20:25:34 EDT 2001


> Working on converting a collection of perl utilities I've written for
> projects to Python.  Am encountering a problem in time conversions; we
> need to process date strings from a YYYY-MM-DDTHH:MM:SS.SSSSSZ format
> (Zulu time = GMT = UTC) into unix epoch date format.  time module does
> not list function which takes as input a time tuple and returns UTC
> based epoch time.  Is there such a module out there somewhere?
> 
> Parsing the string from the ascii format mentioned above into date &
> time chunks is no problem of course, split handles that quite nicely. 
> It's the conversion from a UTC based tuple set -> epoch time value that
> I need.

If I understood your problem, then the following interactive session
might help:

>>> from time import mktime, gmtime, time
>>> mktime(gmtime(time()))
1001545311.0
>>> 

I used gmtime(time()) simply because it produces a UTC time tuple:

>>> gmtime(time())
(2001, 9, 27, 0, 3, 2, 3, 270, 0)
>>> 

I hope this can be of any use for you. Else check out time.__doc__,
where I extracted this info from.

Kudos, Dietmar

-- 
To mail me, remove "nospam.".



More information about the Python-list mailing list