获取当月(月份)天数

const year = 2021;
const month = 8;
new Date(year, month, 0).getDate();

传入年份和月份即可,第三个参数固定写0;即可。

你可能感兴趣的:(时间对象,js获取月份的天数)