[Tutor] problem with time module

Tim Peters tim.peters at gmail.com
Mon Aug 16 04:12:19 CEST 2004


[Dick Moores]
> OK, here's my reasoning. From the doc,
> 
> "mktime( t)
> 
> This is the inverse function of localtime(). Its argument is the
> struct_time or full 9-tuple (since the dst flag is needed; use -1 as the
> dst flag if it is unknown) which expresses the time in local time, not
> UTC. ...
> "

And it really is an inverse:  localtime() takes a timestamp and
converts to a local struct_time, while mktime() does exactly the
opposite.

> If mktime(t) is the inverse of localtime(), I thought this implied that
> the floating point number mktime(localtime()) returned would be
> seconds from the epoch based on my local time. I saw nothing that
> said that all timestamps are based on UTC (although I can see now
> that it's a Good Thing they are). I did understand that time() is based
> on UTC. Therefore I concluded that mktime(localtime()) should be
> about 7 hours less than time().

Unfortunately, the time module consists of thin wrappers around the
pretty miserable time functions defined by the C language.  That's why
"everyone knows" what "seconds from the epoch" <sheesh> means, and
"everyone knows" too that "seconds from the epoch" means UTC.  It
sucks, but that's life.  If it all possible, I'd encourage you to use
the newer datetime module instead.


More information about the Tutor mailing list