Does anyone know how can I get next week date based on this week date? example if I have this thursday date (25/6/2009) how can I use javascript to get next thursday date (2/7/2009)?
+4
A:
Date.prototype.addDays = function (d) {
if (d) {
var t = this.getTime();
t = t + (d * 86400000);
this.setTime(t);
}
};
this_week.addDays(7);
razzed
2009-06-22 06:26:56
I like it...! +1
Cerebrus
2009-06-22 06:29:46
I would let the date prototype alone, though.
subtenante
2009-06-22 06:30:46
Why leave the date prototype alone?
razzed
2009-06-22 06:35:18
You never know which library you'll end up using. You may come to use something defining a addDays method for computing working days. Then you scratch your head.
subtenante
2009-06-22 06:39:41
+3
A:
var firstDay = new Date("2009/06/25");
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);
You can also look at DateJS if you like "fluent" APIs.
Matthew Flaschen
2009-06-22 06:27:26
+3
A:
function nextweek(){
var today = new Date();
var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
return nextweek;
}
subtenante
2009-06-22 06:31:09
Nice - The function is self-documenting and works with edge cases such as leap seconds.
l0b0
2009-06-22 07:20:00