欢迎加入前端交流群交流知识&&获取视频资料:749539640
let today = new Date().getTime() let lastDay = getTimeByDay(30) //获取30天后的日期 let lastTime = formatTime(lastDay) console.log(lastTime);//2019-03-23 /* num 获取当天多少天后的日期 */ function getTimeByDay(num) { return today + 60 * 60 * 1000 * 24 * num; } function formatTime(time) { //new Date(time).toISOString() => 2019-02-23T08:40:35.825Z return new Date(time).toISOString().split('T')[0]; }