tomorrow in yyyymmdd format

Gerhard Häring gerhard at bigfoot.de
Tue Jun 18 20:44:09 EDT 2002


* Bjorn Pettersen <BPettersen at NAREX.com> [2002-06-18 18:36 -0600]:
> > From: Gerhard Häring [mailto:gerhard at bigfoot.de] 
> > Giulio Cespuglio wrote in comp.lang.python:
> > > Hello everybody,
> > > 
> > > We all know that if I want to get the present GMT date in yyyymmdd 
> > > format I should say
> > > 
> > > 	print time.strftime("%Y%m%d", time.gmtime() )
> > > 
> > > Now, what about tomorrow? [...]
> > > 
> > > 	time.strftime("%Y%m%d", time.gmtime(time.time() + 60*60*24))
> > 
> > No, there's nothing better. Unless you're using the DateTime 
> > type from the eGenix mxExtensions:
> 
> 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 ;-)

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))





More information about the Python-list mailing list