Самая аскетичная реализация:
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
How does this function work? It is quite simple. When the Date()
function is given a day number that is greater than the number of days
in the given month of the given year, it wraps the date into the next
month. The getDate() function returns the day of the month, starting
from the beginning of the month that the date is in. So, day 32 of
March is considered to be day 1 of April. Subtracting 1 from 32 gives
the correct number of days in March
Комментариев нет:
Отправить комментарий