Adding unknown variables to time.mktime()

Gustaf Liljegren gustafl at algonet.se
Tue Jun 26 12:59:57 EDT 2001


gustafl at algonet.se (Gustaf Liljegren) wrote:

Sorry all, I made a syntax error (left out the two extra parenteses), but 
it was good to see some examples. As Roman wrote, you only need the six 
first:

>>> t = time.mktime((1999,1,1,1,1,1,-1,-1,-1))
>>> time.ctime(t)
'Fri Jan 01 01:01:01 1999'

I figured that it would be nice if you could leave out as many as you 
wished, from right to left. Maybe mxDateTime can do handle that? Oviously 
mktime can't:

>>> t = time.mktime((1999,-1,-1,-1,-1,-1,-1,-1,-1))
>>> time.ctime(t)
'Thu Oct 29 22:58:59 1998'

Should have been 'Fri Jan 1 00:00:00 1999'.

>>> t = time.mktime((1999,1,-1,-1,-1,-1,-1,-1,-1))
>>> time.ctime(t)
'Tue Dec 29 22:58:59 1998'

Should have been 'Fri Jan 1 00:00:00 1999'.

>>> t = time.mktime((1999,1,1,-1,-1,-1,-1,-1,-1))
>>> time.ctime(t)
'Thu Dec 31 22:58:59 1998'

Should have been 'Fri Jan 1 00:00:00 1999'.

>>> t = time.mktime((1999,1,1,1,-1,-1,-1,-1,-1))
>>> time.ctime(t)
'Fri Jan 01 00:58:59 1999'

Should have been 'Fri Jan 1 01:00:00 1999'.

>>> t = time.mktime((1999,1,1,1,1,-1,-1,-1,-1))
>>> time.ctime(t)
'Fri Jan 01 01:00:59 1999'

Still a second from the thruth. :-)

>>> t = time.mktime((1999,1,1,1,1,1,-1,-1,-1))
>>> time.ctime(t)
'Fri Jan 01 01:01:01 1999'

Yes!

Anyway, thanks again. This is what I need at the moment.

Regards,

Gustaf Liljegren



More information about the Python-list mailing list