2

代码

function getCurrentMonthFirst(){
    let date = new Date();
    date.setDate(1);
    date.setHours(0, 0, 0, 0);
    return date;
}

function getCurrentMonthFLast(){
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    month++;
    if(month > 12) {
        year++;
        month = 1;
    }
    let newDate = new Date(year, month - 1, 1);
    return (new Date(newDate.getTime() - 1000*60*60*24))
}

原因

这个需求蛮常见的,这里特意记录一下


ufdf
6.7k 声望407 粉丝