我想在接下来的两周内为每一天调用一个函数,并传递诸如日和月之类的参数。我使用这种方法:startDate.setDate(startDate.getDate() + 1)
我在这里找到了,但是在循环的前 6 个步骤之后它变得混乱
var date = new Date,
searchDate = new Date,
period = 14;
for(i = 1; i <= period; i++){
searchDate.setDate(date.getDate() + i);
// someFunction(searchDate.getDate(), searchDate.getMonth());
}
什么console.log(i + ": " + searchDate)
返回:
1: Tue Aug 27 2013 17:38:04 GMT+0200
2: Wed Aug 28 2013 17:38:04 GMT+0200
3: Thu Aug 29 2013 17:38:04 GMT+0200
4: Fri Aug 30 2013 17:38:04 GMT+0200
5: Sat Aug 31 2013 17:38:04 GMT+0200
6: Sun Sep 01 2013 17:38:04 GMT+0200 // so far so good
7: Thu Oct 03 2013 17:38:04 GMT+0200 // and after a week it's suddenly October
8: Sun Nov 03 2013 17:38:04 GMT+0100
9: Thu Dec 05 2013 17:38:04 GMT+0100
10: Sun Jan 05 2014 17:38:04 GMT+0100
11: Thu Feb 06 2014 17:38:04 GMT+0100
12: Mon Mar 10 2014 17:38:04 GMT+0100
13: Tue Apr 08 2014 17:38:04 GMT+0200
14: Sat May 10 2014 17:38:04 GMT+0200
对此有任何线索吗?