该解决方案是在Python中,它不应该很难转换为任何其他语言。
def isLeapYear(year):
if year%4 == 0:
if year%100 == 0:
if year%400 == 0:
return True
else:
return False
else:
return True
else:
return False
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
cumDays = [0,31,59,90,120,151,181,212,243,273,304,334] #cumulative Days by month
leapcumDays = [0,31,60,91,121,152,182,213,244,274,305,335] # Cumulative Days by month for leap year
totdays = 0
if year1 == year2:
if isLeapYear(year1):
return (leapcumDays[month2-1] + day2) - (leapcumDays[month1-1] + day1)
else:
return (cumDays[month2-1] + day2) - (cumDays[month1-1] + day1)
if isLeapYear(year1):
totdays = totdays + 366 - (leapcumDays[month1-1] + day1)
else:
totdays = totdays + 365 - (cumDays[month1-1] + day1)
year = year1 + 1
while year < year2:
if isLeapYear(year):
totdays = totdays + 366
else:
totdays = totdays + 365
year = year + 1
if isLeapYear(year2):
totdays = totdays + (leapcumDays[month2-1] + day2)
else:
totdays = totdays + (cumDays[month2-1] + day2)
return totdays
>如果某一年是闰年,并且具有计算两个日期之间的天数的函数,则我已具有计算函数的功能。
我只能说,我当然希望你正在使用一个良好的固体库,因为你应该为解决整个问题,以及.. – Tim 2009-07-16 23:38:05
“我已经有函数calcualte如果一个特定的一年是一个闰年和以及计算两个日期之间的天数的函数。“ - 听起来像是我最喜欢的方式。 – 2009-07-17 00:00:01