户枢不蠹

自定义函数,自动获取每月天数!

户枢不蠹Lv.2入道 发布于 最后回复 分享
1 回复958 浏览

image.png

function getMonthLength(date) {
let d = new Date(日期);
// 将日期设置为下月一号
d.setMonth(d.getMonth()+1);
d.setDate('1');
// 获取本月最后一天
d.setDate(d.getDate()-1);
return d.getDate();
}
return getMonthLength(日期)

效果就是选择日期的时候,自动计算该时间的天数。