日期:2014-05-16  浏览次数:20359 次

帮我算下时间,谢谢了 `
我现在有一个天数.
和一个日期.我想让这个日期加上这个天数得到一个日期.
例:
int   date1   =   2;
var   date2   =   2007-08-09;
var   date3   =   date1+date2   =   ****-**-**;
谢谢了``帮帮我``在先等答案;

------解决方案--------------------
<script>


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-1,date1Day);

var ccc=new Date(firstDate.getTime()+days*1000*60*60*24)
var result=ccc.getYear()+ "- "+(ccc.getMonth()+1)+ "- "+ccc.getDate();
alert(result)

}
addDays( '2007-08-09 ', '2 ')
addDays( '2007-01-31 ', '1 ')
</script>
------解决方案--------------------
var date1 = 30;
var date2 = new Date(2007,08,09);
date2.setDate(date2.getDate() + date1);
alert(date2.getYear() + "- " + date2.getMonth() + "- " + date2.getDate());
------解决方案--------------------
http://www.blogjava.net/mxx/archive/2006/09/27/72159.html

dateAfter
------解决方案--------------------
<script>
function addDays(dateStr,days){
var dateArr=dateStr.split( "- ");
firstDate=new Date(dateArr[0],dateArr[1]-1,dateArr[2]);
var date2=new Date(firstDate.getTime()+days*1000*60*60*24)
var dateStr2=date2.getYear()+((date2.getMonth()+1)> 10? "- ": "-0 ")+(date2.getMonth()+1)+ "- "+date2.getDate();
alert(dateStr2)
}
addDays( '2007-08-09 ', '2 ');
</script>
------解决方案--------------------
var dateStr2=date2.getYear()+((date2.getMonth()+1)> 10? "- ": "-0 ")+(date2.getMonth()+1)+ "- "+date2.getDate();
=======>
var dateStr2=date2.getYear()+((date2.getMonth()+1)> =10? "- ": "-0 ")+(date2.getMonth()+1)+(date2.getDate()> =10? "- ": "-0 ")+date2.getDate();