converting a timezone-less datetime to seconds since the epoch

Chris Withers chris at
Thu Mar 18 14:44:53 CET 2010

Hey Chris,

Chris Rebert wrote:
>> def timestamp(dttm):
>>    return time.mktime(dttm.timetuple())
> from calendar import timegm
> def timestamp(dttm):
>     return timegm(dttm.utctimetuple())
> #the *utc*timetuple change is just for extra consistency
> #it shouldn't actually make a difference here

Ah, right. What on earth is timegm doing in calendar?
No way I ever would have thought to look there...

I wonder what the best way to get this stuff documented in the datetime 
modules docs is?


Simplistix - Content Management, Batch Processing & Python Consulting

More information about the Python-list mailing list