方法一:自己根据年份判断是否闰年,再根据月份得出天数
export const getDaysInMonth = (year, month) => { let isLeapYear = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0; if (parseInt(month, 10) === 2) { return isLeapYear ? 29 : 28; } return Math.ceil(Math.abs(month - 7.5)) % 2 + 30; }
方法二:利用原生new Date()方法获取
export const getDaysInMonth =(year, month) =>{
let d = new Date(year,month,0);
return d.getDate();
}