function getStandTimer(num){ let standTime = null; let thisData = new Date(); let msec = thisData.getTime() + 86400000*num; let data = new Date(msec) let year = data.getFullYear(); let month = data.getMonth()+1; let day = data.getDate(); if(month<10){month = '0' + month} if(day<10){day = '0' + day}; standTime = year + '-' + month + '-' + day; return standTime; }
使用:
当前时间:var nowTime = getStandTimer(0)
7天后:var sevenAfterTime = getStandTimer(7)
6天前:var sixBeforTime = getStandTimer(-6)