Day of Year Behaviour

Richard Townsend nospam at here.com
Fri Oct 1 13:25:15 EDT 2004


On 30 Sep 2004 15:55:53 -0700, Hector Villafuerte wrote:

> 
> I'm using the time module without success:
>>>> time.localtime(time.mktime((2004, 0, 0, 0, 0, 0, 0, 1, 0)))
> (2003, 11, 30, 0, 0, 0, 6, 334, 0)
> 

If you pass the year-day as the third item in the 9-tuple, then
localtime(mktime()) should normalise the date correctly:

>>> time.localtime(time.mktime((2004, 1, 1, 0, 0, 0, 0, 0, 0)))
(2004, 1, 1, 0, 0, 0, 3, 1, 0)
>>> time.localtime(time.mktime((2004, 1, 33, 0, 0, 0, 0, 0, 0)))
(2004, 2, 2, 0, 0, 0, 0, 33, 0)
>>> time.localtime(time.mktime((2004, 1, 365, 0, 0, 0, 0, 0, 0)))
(2004, 12, 30, 0, 0, 0, 3, 365, 0)
>>> 

But, as others have stated, the datetime module is probably the better way
to go.

-- 
Richard



More information about the Python-list mailing list