获取月份的最后一天

发布时间 2023-11-29 21:31:30作者: 张尊娟

new Date(year, month, 0).getDate()

 // 获取月份的最后一天
        let now = new Date()
        let year = now.getFullYear()
        let month = now.getMonth() - 1

        function lastMonthday(year, month) {
            let lastDay = new Date(year, month, 0).getDate()
            console.log(lastDay);
            return lastDay
        }

        lastMonthday(year, month)
        lastMonthday('2023', '10')