Gets the number of days in the given month
of the specified year
.
Date
constructor to create a date from the given year
and month
.0
to get the last day of the previous month, as months are zero-indexed.Date.prototype.getDate()
to return the number of days in the given month
.const daysInMonth = (year, month) => new Date(year, month, 0).getDate();
daysInMonth(2020, 12)); // 31
daysInMonth(2024, 2)); // 29
JavaScript, Date
Gets the day of the year (number in the range 1-366) from a Date
object.
JavaScript, Date
Calculates the date after adding the given number of business days.
JavaScript, Date
Returns the human-readable format of the given number of milliseconds.