[前端填坑]js--獲取上個月的年月 和 上個月月底日期
阿新 • • 發佈:2019-02-17
function getLastMonth(){//獲取上個月日期
var date = new Date;
var year = date.getFullYear();
var month = date.getMonth();
if(month == 0){
year = year -1;
month = 12;
}
return year+"年"+month+"月";
}
/** * 獲取上個月月底日期 */ function getLastMonthAndDay(){ var nowDate = new Date(); var year = nowDate.getFullYear(); var month = nowDate.getMonth(); if(month == 0){ month = 12; year = year - 1; } var lastDay = new Date(year,month,0); var yyyyMMdd = year+"年"+month+"月"+lastDay.getDate()+"日"; console.log(yyyyMMdd); }