0

只是想要每两周添加一次数字的帮助。

比方说,

Start date : Jan 15, 2012  
End date : May 15, 2012  
Value : 300.00

我想要完成的是,每个月的第 15 天和最后一天 300 将乘以 2012 年 5 月 15 日之前的第 15 天和最后一天

所以

Jan 15, 2012 to Jan 31,    2012 the value must be 300.00  
Feb 01, 2012 to Feb 15,    2012 the value must be 600.00  
Feb 16, 2012 to Feb 28/29, 2012 the value must be 900.00  
Mar 01, 2012 to Mar 15,    2012 the value must be 1200.00  
Mar 16, 2012 to Mar 31,    2012 the value must be 1500.00  
Apr 01, 2012 to Apr 15,    2012 the value must be 1800.00  
Apr 16, 2012 to Apr 30,    2012 the value must be 2100.00  
May 01, 2012 to May 15,    2012 the value must be 2400.00  

希望你明白我的意思。

希望得到您的帮助,谢谢。

4

1 回答 1

0

You can loop as long as you have whole months, then check if there is a half month to add at the end:

var date = startDate;
var sum = 0;
while (date < endDate) {
  sum += value * 2;
  date.setMonth(date.getMonth() + 1);
}
if (date < endDate) sum += value;
于 2012-04-27T06:31:07.507 回答