Я пользуюсь этой функцией, но мне бы хотелось узнать, какой самый эффективный и точный способ ее получить.
function daysInMonth(iMonth, iYear) { return 32 - new Date(iYear, iMonth, 32).getDate(); }
Учитывая високосные годы:
function (year, month) { var isLeapYear = ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0); return [31, (isLeapYear ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; }
function numberOfDays(iMonth, iYear) { var myDate = new Date(iYear, iMonth + 1, 1); //find the fist day of next month var newDate = new Date(myDate - 1); //find the last day return newDate.getDate(); //return # of days in this month }