Javascript Calculate Date Week By Week
Hy guys, i have write this javascript code for calculate date for any day of week progressively. But i ahve error when the code must be calculate the end of month: example after 31
Solution 1:
Just add the hours*minutes*seconds*milliseconds
to today's date, and you get tomorrow's date, and so on.
var tomorrowsDate = newDate(newDate().getTime() + 24 * 60 * 60 * 1000);
Solution 2:
To calculate the date for one day ahead you can use Date.prototype.setDate()
So to calculate all dates from today and week ahead, you can do something like this:
var currentDate = newDate();
var stringDate = [];
for (var i = 0; i < 7; ++i) {
currentDate.setDate(currentDate.getDate() + 1);
stringDate[i] = currentDate.getUTCDate() + "/" + (currentDate.getMonth() + 1) + "/" + currentDate.getFullYear();
}
console.log(stringDate);
// 0: "28/7/2015"// 1: "29/7/2015"// 2: "30/7/2015"// 3: "31/7/2015"// 4: "1/8/2015"// 5: "2/8/2015"// 6: "3/8/2015"
Post a Comment for "Javascript Calculate Date Week By Week"