我有一个问题,想知道是否有人可以告诉我一些关于原因的见解。以下代码用于将日期增加一周:
while (c.getStamp() < b.getStamp()) {
var f = this.getWeek(c);
e.push(f);
c = (c.getStamp() + 604800).toDate();
}
...
Date.prototype.getStamp = function() {
return Math.round(this.getTime() / 1e3);
};
Number.prototype.toDate = function() {
return new Date(this * 1e3);
};
我正在尝试让以下内容起作用,但它会创建一个连续的循环:
while (c.getStamp() < b.getStamp()) {
var f = this.getWeek(c);
e.push(f);
c = new Date(c.getFullYear(), c.getMonth(), c.getDate + 7, 0, 0, 0);
}
其中 c = JS 日期,即 05/01/12
和 b = JS 日期,即 05/31/12
最佳答案
您在 c.getDate
之后错过了 ()
。
除此之外,您还可以这样做:
c.setTime(c.getTime()+7*24*60*60*1000); // adds 1 week to the date
关于javascript - 添加 1 周的 JS 日期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10826621/