// 获取月初值和月末值
const getMonthRange = (date: Date | string) => {
    let startDate: Date
    if (typeof date === 'string') {
        startDate = new Date(date)
    } else {
        startDate = date
    }
    const endDate = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0)
    const start = new Date(startDate.getFullYear(), startDate.getMonth(), 1).toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')
    const end = endDate.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')
    return { start, end }
}
最后修改:2023 年 11 月 18 日
如果觉得我的文章对你有用,请随意赞赏