前n个月第一天
function getBeforeMonth(n) {
let yearCount = Math.floor(n / 12);
let modMonth = n % 12;
let nowdays = new Date();
let year = nowdays.getFullYear();
year = year - yearCount
// console.log("yearcounttttt",yearCount,modMonth)
let month = nowdays.getMonth()+1;
let _month = month - modMonth
// console.log("大家的加分加分加分",month,_month)
if (_month <= 0) {
_month = 12 + _month
year = year - 1
}
if (_month < 10) {
_month = "0" + _month;
}
let firstDay = year + "-" + _month + "-" + "01";
let myDate = new Date(year, _month, 0);
let lastDay = year + "-" + _month + "-" + myDate.getDate();
// console.log("喜喜喜喜喜喜",firstDay)
return firstDay
// console.log("双双",lastDay)
}
获取前n天的字符串
function getDayStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate()+AddDayCount);
var y = dd.getFullYear();
var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);
var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();
return y+"-"+m+"-"+d;
}