JS获取指定日期之前/之后XX天的日期
/** * 获取日期, * day,正数向前推X天,负数向后推X天 */ function getTime(day) { var lw = new Date(new Date() - 1000 * 60 * 60 * 24 * day);//最后一个数字30可改,30天的意思 var lastY = lw.getFullYear(); var lastM = lw.getMonth() + 1; var lastD = lw.getDate(); var startdate = lastY + "-" + (lastM < 10 ? "0" + lastM : lastM) + "-" + (lastD < 10 ? "0" + lastD : lastD);//三十天之前日期 return startdate } //例子 console.log(getTime(30)) console.log(getTime(20)) console.log(getTime(-3)) console.log(getTime(32))
参考转载:
https://blog.csdn.net/qq_35250826/article/details/87840571
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案