3
06/11/2024 8:58 am
Rozpoczęcie tematu
I need to write JavaScript (JS) function that calculates the date of the next day by given year, month and day.
The input comes as three number parameters:
- The first element is the year
- The second is the month
- The third is the day
Examples:
Input:
2016, 9, 30
Output:
2016-10-1
The output should be returned as a result of your function.
1 Odpowiedź
2
06/11/2024 8:58 am
Here is the solution my friend:
function calcNextDay(year, month, day) {
var date = new Date(year, month - 1, day);
var oneDay = 24 * 60 * 60 * 1000;//86 400 000 milliseconds in one day
var nextDate = new Date(date.getTime() + oneDay);
console.log(nextDate.getFullYear() + "-" + (nextDate.getMonth() + 1) + "-" + nextDate.getDate());
}
calcNextDay(2016, 9, 30);
