JavaScript计算日期加上指定天数后的日期转自:http://blog.chinaunix.net/uid/257761.html
//判断年份是否是闰年 function isLeapYear(year){ if(year%400==0){ return false; }else if(year%4==0){ return true; }else{ return false; } } //计算日期加上天数后的日期 function addDays(date1,days){ var monthDays=[0,3,0,1,0,1,0,0,1,0,0,1]; var regexp=/^(\d{1,4})[-|\.]{1}(\d{1,2})[-|\.]{1}(\d{1,2})$/; regexp.test(date1); var date1Year=RegExp.$1; var date1Month=RegExp.$2; var date1Day=RegExp.$3; firstDate=new Date(date1Year,date1Month,date1Day); firstDate.setTime(firstDate.getTime()+days*1000*3600*24); var diff=0; for(j=date1Year;j<=firstDate.getYear();j++){ if(isLeapYear(j)){ monthDays[1]=2; }else{ monthDays[1]=3; } for(i=date1Month-1;i<firstDate.getMonth()-1;i++){ diff=diff+monthDays[i]; } } result=firstDate.getYear()+"-"+firstDate.getMonth()+"-"+firstDate.getDate(); if(diff!=0){ result=addDays(result,diff); } return result; }