function getBeforeDate(days){ var now=new Date().getTime(); var ago=now-86400000*days;//一天的毫秒数为86400000 var agoData= new Date(ago); var year = agoData.getFullYear(); var mon = agoData.getMonth() + 1; var day = agoData.getDate(); mon=mon<10? '0'+mon:mon; day=day<10? '0'+day:day; var date=year+'-'+mon+'-'+day; return date; }; console.log(getBeforeDate(7));//昨天的日期