date / time
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Wed Apr 3 08:19:04 EST 2002
mixo wrote:
> By "valid" date I meant subtracting a day, and then finding that the
> new date does actually exsist.
The date returned by gmtime should always be valid. To check an arbitrary
date, try
>>> (year, month, day) == time.gmtime(time.mktime((year, month, day, 1, 1,
1, 1, 1, 0)))[:3]
1
> One note/question on time.gmtime():
> +++++++++++
> time.gmtime( time.mktime(time.strptime(date,"%Y-%m-%d"))-(24*60*60))
> +++++++++++
>
> returns
> +++++++++++
> (2002, 2, 27, 22, 0, 0, 2, 58, 0)
> +++++++++++
>
> There is a day missing. If you add 1 second , i.e ((24*60*60)+1) you get
> the required dated. What's going on?
It's probably something to do with your timezone. You can work strictly
in GMT if you ignore strptime and do
>>> year, month, day = map(int,re.findall('(\d+)', '2002-03-01'))
>>> time.gmtime(time.mktime((year, month, day, 0, 0, 0, 0, 0, 0))-24*3600)
(2002, 2, 28, 0, 0, 0, 3, 59, 0)
Graham
More information about the Python-list
mailing list