728x90
function getLastDayOfMonth(year, month) {
const months = [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'
];
const date = new Date(year, month + 1, 0);
return `Last day of ${months[month]}, ${year} is ${date.getDate()}`;
}
console.log( getLastDayOfMonth(2012, 0) ); // 31
console.log( getLastDayOfMonth(2012, 1) ); // 29
console.log( getLastDayOfMonth(2013, 1) ); // 28

+ Recent posts