SOURCE

function addMonth(begin_date,monthNum){
    
    var arr=begin_date.split('-');
    var year=parseInt(arr[0]);
    var month=parseInt(arr[1]);
    month=month+monthNum;
    if(month>12){
        var yearNum=parseInt((month-1)/12);
        month=month%12==0?12:month%12;
        year+=yearNum;
    }else if(month<=0){
        month=Math.abs(month);
        var yearNum=parseInt((month+12)/12);
        year-=yearNum;
    }
    month=month<10?"0"+month:month;
    result= year+"-"+month+"-"+arr[2];
    return result
}

var begin_date="2021-12-01";
var monthNum=6;
a=addMonth(begin_date,monthNum);
console.log(a)
console 命令行工具 X clear

                    
>
console