一:JS 日期加减几天函数
var a = getAddTime(7, '2024-01-01');
console.log(a )
function getTime(num, dateT) {
var dateCur = new Date(dateT); // 转成时间格式
var timeCur =
dateCur.getFullYear() +
"-" +
(dateCur.getMonth() + 1) +
"-" +
dateCur.getDate();
var dateTea = new Date(dateCur);
dateTea .setDate(dateCur.getDate() + num); // 设置dateTea的时间加七天
var y = dateTea .getFullYear();
var m = dateTea .getMonth() + 1;
var d = dateTea .getDate();
m = m < 10 ? "0" + m: m;
d = d < 10 ? "0" + d: d;
var day = y + "-" + m + "-" + d;
return day;
};
03-30
2187
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-28
7311
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-30
619
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-04
6350
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-28