function getDays(year,month){
var month = Number(month) - 1;
let days = [31,28,31,30,31,30,31,31,30,31,30,31];//把12个月的天数固定成数组
if((year % 4 ===0) && (year %100 !==0 || year & 400 ===0)){//计算闰年将2月改成29天
days[1] = 29
}
return days[month]
}
console.log(getDays(2022,2));
网友评论