// 获取指定日期字符串上一月字符串:YYYY-MM-DD
function getPrevMonthFormatDate(formatDate) {
if (formatDate.length != 10) {
return null
}
let year = Number(formatDate.substr(0, 4));
let month = Number(formatDate.substr(5, 2));
let day = Number(formatDate.substr(8, 2));
if (month == 1)
{
year = year - 1;
month = 12;
}
else
{
month = month - 1;
}
return formatInteger(year, 4) + '-' + formatInteger(month, 2) + '-' + formatInteger(day, 2);
}
// 获取指定日期字符串下一月字符串:YYYY-MM-DD
function getNextMonthFormatDate(formatDate) {
if (formatDate.length != 10) {
return null
}
let year = Number(formatDate.substr(0, 4));
let month = Number(formatDate.substr(5, 2));
let day = Number(formatDate.substr(8, 2));
if (month == 12)
{
year = year + 1;
month = 1;
}
else
{
month = month + 1;
}
return formatInteger(year, 4) + '-' + formatInteger(month, 2) + '-' + formatInteger(day, 2);
}
其中 formatInteger 见 JavaScript 使用指定字符格式化整数_hzgisme的博客-CSDN博客