function getThreeMonthAgoDate() {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
// const currentDate = year + "-" + month + "-" + day;
// console.log('***.currentDate',currentDate)
const days = parseInt(month) < 3 ? new Date(year-1, month+12-3, 0) : new Date(year, month-3, 0);
const maxDays = days.getDate(); //对应的三个月前的month,这个月的最大天数
const yearAgo = parseInt(month) < 3 ? year-1 : year;
const monthAgo = parseInt(month) < 3 ? month+9 : month-3;
const dayAgo = parseInt(maxDays) < parseInt(day) ? maxDays : day;
const threeMonthsAgoDate = yearAgo + "-" + monthAgo + "-" + dayAgo;
return threeMonthsAgoDate;
}
eg.
currentDate = "2024-5-31"
threeMonthsAgoDate = "2024-2-29"