Javascript is reporting that February has 31 days. The code below shows that the second month has more days than it should. What's going on?
var currentDate = new Date(2018, 2, 4);
function getDaysInMonth(month, year) {
var date = new Date(year, month, 1);
var days = [];
while (date.getMonth() === month) {
days.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return days;
}
var dayArr = getDaysInMonth(currentDate.getMonth(), currentDate.getFullYear());
alert('month: '+currentDate.getMonth()+' year: '+currentDate.getFullYear()+' days: '+dayArr.length);