有谁知道如何根据本周日期获得下周的日期?例如,如果我有这个星期四的日期(25/6/2009),我如何使用javascript来获得下一个星期四的日期(2009年2月7日)?
Mat*_*hen 56
var firstDay = new Date("2009/06/25");
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
Run Code Online (Sandbox Code Playgroud)
如果您喜欢"流利的"API,也可以查看DateJS.
glm*_*ndr 35
function nextweek(){
var today = new Date();
var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
return nextweek;
}
Run Code Online (Sandbox Code Playgroud)
Vol*_*ker 11
function dateObject.getNextWeekDay返回对象自己的日期之后的下一个工作日.
Date.prototype.getNextWeekDay = function(d) {
if (d) {
var next = this;
next.setDate(this.getDate() - this.getDay() + 7 + d);
return next;
}
}
var now = new Date();
var nextMonday = now.getNextWeekDay(1); // 0 = Sunday, 1 = Monday, ...
var secondNextMonday = new Date(nextMonday).getNextWeekDay(1);
console.log('Next Monday : ' + nextMonday);
console.log('Second Next Monday : ' + secondNextMonday);Run Code Online (Sandbox Code Playgroud)
Date.prototype.addDays = function (d) {
if (d) {
var t = this.getTime();
t = t + (d * 86400000);
this.setTime(t);
}
};
this_week.addDays(7);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47430 次 |
| 最近记录: |