直接上代码
import dayjs from 'dayjs'
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
dayjs.extend(isSameOrBefore)function getCurrentMonthDays(month) {const firstDay = dayjs().startOf('month');const lastDay = dayjs().endOf('month');const allDatesInMonth = [];let currentDate = firstDay;while (currentDate.isSameOrBefore(lastDay, 'day')) {allDatesInMonth.push(currentDate.format('DD'));currentDate = currentDate.add(1, 'day');}return allDatesInMonth
}
如何使用呢?
getCurrentMonthDays('2024-07')