script for seconds in given month?
attn.steven.kuo at gmail.com
attn.steven.kuo at gmail.com
Mon Apr 16 14:11:08 EDT 2007
On Apr 16, 10:18 am, s... at pobox.com wrote:
> Matt> from time import mktime
> Matt> def secondsInMonth(year, month):
> Matt> s1 = mktime((year,month,1,0,0,0,0,0,-1))
> Matt> s2 = mktime((year,month+1,1,0,0,0,0,0,-1))
> Matt> return s2-s1
>
> Probably won't work if month==12. ;-)
>
> Skip
Actually, mktime as described in the C Standard does not
restrict members such as tm_mon of struct tm to the
range 0-11 (1-12 for the corresponding entry in the
time tuple in Python). So the underlying struct in
CPython may be normalized and return a perfectly valid
time even if month is > 12.
--
Regards,
Steven
More information about the Python-list
mailing list