tomorrow in yyyymmdd format

Conrad zneptune at zexcite.zcom
Wed Jun 26 13:43:36 EDT 2002


Years ago, Nostradamus predicted that on Tue, 18 Jun 2002 20:52:25 -0500,
Gerhard Häring would write, saying:

> * Sean 'Shaleh' Perry <shalehperry at attbi.com> [2002-06-18 18:38 -0700]:
>> >> 
>> >> Sure there is :-) time.mktime() can take a "malformed" time tuple
>> >> and do something sensible with it. You can therefore get a time
>> >> tuple from gmtime, add one to the day position and call
>> >> time.mktime() on the result:
>> >> 
>> >> >>> x = (2002, 2, 29, 0, 31, 42, 2, 170, 0)
>> >> >>> time.gmtime(time.mktime(x))
>> >> (2002, 3, 1, 7, 31, 42, 4, 60, 0)
>> >> >>>
>> >> >>>
>> > Pure luck that this works. Don't complain if it stops workin in
>> > Python 2.7 and your code breaks ;-)
>> > 
>> > 
>> actually that is a function of the mktime() function in the C library
>> which the python module wraps.  Based on my reading of a man page or
>> two this behaviour seems guaranteed by POSIX.  Now, the assumption made
>> is the mktime() function on YOUR system follows POSIX.
> 
> Fine. I've just read the Python documentation which doesn't make this
> guarantee. I'll leave it to others to check if this works on win32,
> MacOS, as I'm using mxDateTime for this kind of tasks, anyway.
> 
> Gerhard


Hmm  - here's what I've done - a bit klutzy but it seems to work:

from time import *
one_day = 60*60*24                       # number of seconds in day
   # make a julian for tomorrow -
   # note: depending on what you want be careful around midnight!
tomorrow = mktime(localtime()) + one_day
print 'tomorrow is',localtime(tomorrow)
print 'today is',localtime()


tomorrow is (2002, 6, 27, 10, 42, 11, 3, 178, 1)
today is (2002, 6, 26, 10, 42, 11, 3, 178, 1)

Conrad



More information about the Python-list mailing list