// 获取前一天所在月份
//这里日期格式为'20190805',如果是其他格式需要转为这种
var date = '20190805';
//初始化前一天所在月份,一般都是前六位
var yMonth = date.substring(0,6);
//不是前六位的状况
if (date.substring(6,8) == '01') { //1号
if (date.substring(4,6) == '01') { //1月
//前一天所在月份为前一年的12月
yMonth = date.substring(0,4) - 1 + '12';
} else {
//前一天所在月份为当前月份减一
yMonth = date.substring(0,6) - 1;
}
}
JavaScript获取选中日期前一天所在的月份
最新推荐文章于 2023-09-22 10:07:51 发布