js 利用Date对象得到某个月份
function getMonth(addMonth) {
var date = new Date();
var m = date.getMonth() + 1;
var y = date.getFullYear();
if (m + addMonth <= 0) {
yearCount = Math.floor((0 - (m + addMonth)) / 12) + 1;
y = y - yearCount;
m = m + 12 * yearCount + addMonth;
} else if (m + addMonth > 12){
yearCount = Math.floor((m + addMonth) / 12);
y = y + yearCount;
m = m - 12 * yearCount + addMonth;
}
m= m > 9 ? m:'0'+m;
return y + "-" + m;
}
var res = getMonth(-1)
console.log(res)