SOURCE

console 命令行工具 X clear

                    
>
console
var date = new Date();
// var year;
// var month;
var day;
// var lastDay;

//得到当月年月和最后一天
function getNowMonth() {
    var dat = [];
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    day = date.getDate();
    var lastDay = getLastDay(year, month);
    // console.log(lastDay)
    dat.push(year, month, day, lastDay);
    console.log(dat)
}

//得到上月年月和最后一天
function getPreMonth() {
    var dat = [];
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth();
    day = date.getDate();
    if (month == 0) {
        year = year - 1;
        month = 12;
    }
    var lastDay = getLastDay(year, month);
    // console.log(lastDay)
    dat.push(year, month, day, lastDay);
    console.log(dat)
}


//根据年月获取该月最后一天
function getLastDay(year, month) {
    var new_year = year;    //取当前的年份          
    var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)          
    if (month > 12) {
        new_month -= 12;        //月份减          
        new_year++;            //年份增          
    }
    var new_date = new Date(new_year, new_month, 1);                //取当年当月中的第一天          
    return (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate();//获取当月最后一天日期          
}


function PregeMonth(date) {
    if (!date) {
        console.log(111111)
    } else {
        console.log(date)
    }
    //开始做判断
    // if (day > 0 && day < 11) {
    //     getPreMonth();
    //     // month = getNowMonth();
    // } else if (day > 10 && day < 21) {
    //     getNowMonth();
    // } else {
    //     getNowMonth();
    // }
}

PregeMonth();

var itm=new Date('2019-03-30');
console.log(itm.getDate())