//获取当月; function getMonths(mons, today) { var d = new Date(); var nowYear = d.getFullYear().toString();//今年 var nowMonth = timeAdd0((d.getMonth() + 1 + Number(mons)).toString());//当月 var nowDay = timeAdd0(d.getDate().toString());//当日 if (today == "0") { var now = nowYear + "-" + nowMonth + "-" + nowDay;//今日标准时间; 2020-09-02 } else { var now = nowYear + "-" + nowMonth + "-" + "01";//今日标准时间; 2020-09-02 } return now; } //补齐十位数; function timeAdd0(str) { if (str.length <= 1) { str = '0' + str; } return str }
Done!