SOURCE

function dataInit(year,month){
    month= month - 1;
    var startWeek =1;
    var prevMonth = new Date(Date.UTC.apply(Date, [year,month,0])),
        day = prevMonth.getUTCDate();
    prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - startWeek + 7) % 7);
    var nextMonth = new Date(prevMonth);
    if (prevMonth.getUTCFullYear() < 100) {
        nextMonth.setUTCFullYear(prevMonth.getUTCFullYear());
    }
    nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
    nextMonth = nextMonth.valueOf();
    
    var r=[];
    while(prevMonth.valueOf() < nextMonth){
        var type='day';
        if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() === year && prevMonth.getUTCMonth() < month)) {
            type='old day';
        } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() === year && prevMonth.getUTCMonth() > month)) {
            type='next day';
        }
        var content = prevMonth.getUTCDate();
        r.push({
            data:content,
            type:type
        });
        prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
    }
    return r;
}

console.log(dataInit(2020,8));
console 命令行工具 X clear

                    
>
console