过去N天,爽得一批
//过去7天,过去14天,过去30天 想要过去几天参数就传几就行了console.log(this.getBeforeDate(1),'88888') // 2023-03-02 console.log(this.getBeforeDate(5),'88888') // 2023-02-26
getBeforeDate(n) { var n = n; var d = new Date(); var year = d.getFullYear(); var mon = d.getMonth() + 1; var day = d.getDate(); if (day <= n) { if (mon > 1) { mon = mon - 1; } else { year = year - 1; mon = 12; } } d.setDate(d.getDate() - n); year = d.getFullYear(); mon = d.getMonth() + 1; day = d.getDate(); let s = year + "-" + (mon < 10 ? "0" + mon : mon) + "-" + (day < 10 ? "0" + day : day); return s; },
//
标签:天都,14,过去,mon,year,var,day,getDate From: https://www.cnblogs.com/myfirstboke/p/17174945.html