tomorrow in yyyymmdd format
Bjorn Pettersen
BPettersen at NAREX.com
Wed Jun 26 15:59:56 EDT 2002
> From: Conrad [mailto:zneptune at zexcite.zcom]
>
> 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()
The problem with this approach is that it doesn't account for DST. This may or may not be a problem for you...
00h15+24-1'ly y'rs
-- bjorn
More information about the Python-list
mailing list