SOURCE

// var y = (new Date()).getFullYear();
// var m = 1; //8月
// var la = new Date(y, m ,1-1); //结束时间
// var start = new Date(y,m,1); //开始时间
// console.log(start)

// var year = la.getFullYear();
// var month1 = la.getMonth()+1;
// var day = la.getDate();
// var month2 = start.getMonth()

// if(month1.toString().length == 1 || month2.toString().length == 1){
//     month1 = "0"+month1;
//     month2 = "0"+month2;
// }

// console.log(year+month1+day);
// console.log(year+month2+"01");
// console.log("=========================================")

// for(var i =0; i<12; i++){
//     var y = (new Date()).getFullYear();
//     var m = (i+1); //8月
//     var la = new Date(y, m ,1-1);
//    console.log(la.getFullYear()+"-"+(la.getMonth()+1)+"-"+la.getDate())
// }

//封装成方法
function getFirstAndLastMonth(m){

    var y = (new Date()).getFullYear();
    var date = new Date(y, m ,1-1); //结束时间
    

    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    if(month.toString().length == 1){
        month = "0"+month;
    }

    var first = year+"-"+month+"-"+"01";
    var last=  year+"-"+month+"-"+day;

    var info={"First":first,"Last":last};
    return info;
}
// console.log(getFirstAndLastMonth(1)["First"]);
// console.log(getFirstAndLastMonth(1)["Last"]);
for(var i = 0; i < 12; i++){
    console.log(getFirstAndLastMonth(i+1));
}

console 命令行工具 X clear

                    
>
console