给定月份的秒数? [英] script for seconds in given month?
问题描述
有没有人碰巧知道一个脚本,如果我给它一个月和一年,它会在一个月内返回
秒数?
我的python有点弱,但是如果有人可以提供一些建议
我想我可以自己处理它,或者如果有人碰巧知道一个
脚本已经写好了,我会非常感谢
感激不尽。
谢谢!
-Ed
>
Hi, does anyone happen to know of a script that would return the
number of seconds in a month if I give it a month and a year?
My python is a little weak, but if anyone could offer some suggestions
I think I could handle it myself, or if anyone happens to know of a
script already written that performs this I would be extremely
grateful.
Thanks!
-Ed
推荐答案
4月16日下午12:22,edfialk < edfi ... @ gmail.comwrote:
On Apr 16, 12:22 pm, "edfialk" <edfi...@gmail.comwrote:
有没有人碰巧知道会返回
号的脚本如果我给它一个月和一年一个月的秒数?
我的python有点弱,但如果有人可以提供一些建议
我我想我可以自己处理它,或者如果有人碰巧知道已经写好的b / b $ b脚本执行此操作我会非常感激。
感激不尽。
Hi, does anyone happen to know of a script that would return the
number of seconds in a month if I give it a month and a year?
My python is a little weak, but if anyone could offer some suggestions
I think I could handle it myself, or if anyone happens to know of a
script already written that performs this I would be extremely
grateful.
可能有复杂的答案,但你有没有试过
类似于:
monthDays = {''Jan'':31,''Feb'':28,..}
秒= 60 * 60 * 24 * monthDays [thisMonth]
如果(thisMonth ==''Feb''
and isLeap(thisYear)):
secs + = 60 * 60 * 24
return secs
?
Probably there are sophisticated answers, but have you tried
something like:
monthDays={''Jan'':31,''Feb'':28, ..}
secs=60*60*24*monthDays[thisMonth]
if (thisMonth==''Feb''
and isLeap(thisYear)):
secs+=60*60*24
return secs
?
4月16日下午6:22,edfialk < edfi ... @ gmail.comwrote:
On Apr 16, 6:22 pm, "edfialk" <edfi...@gmail.comwrote:
有没有人碰巧知道会返回
号的脚本如果我给它一个月和一年一个月的秒数?
Hi, does anyone happen to know of a script that would return the
number of seconds in a month if I give it a month and a year?
这样的事可能有效,它应该事件正确处理DST。
你可以读一下mktime()如果你想确定。
从时间导入mktime
def secondsInMonth(年,月):
s1 = mktime((年,月,1,0,0,0,0,0,-1))
s2 = mktime((年,月+ 1) ,1,0,0,0,0,0,-1))
返回s2-s1
/ Matt
>
Matt from time import mktime
Mattdef secondsInMonth(年,月):
Matt s1 = mktime((年,月,1,0,0,0,0,0,-1))
马特s2 = mktime((年,月+ 1,1,0,0, 0,0,0,-1))
马特返回s2-s1
如果月份== 12,可能不会工作。 ;-)
Skip
Mattfrom time import mktime
Mattdef 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
这篇关于给定月份的秒数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!