当前位置: 代码迷 >> Web前端 >> 依据月份增加日期
  详细解决方案

依据月份增加日期

热度:107   发布时间:2012-10-26 10:30:59.0
根据月份增加日期
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> 根据月份增加日期 </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <SCRIPT TYPE="text/javascript">
   function loadDate(){
     var myDate = new Date();
     var year=myDate.getFullYear();   //获取完整的年份(4位,1970-????)
     var month=myDate.getMonth()+1;      //获取当前月份(0-11,0代表1月)
     var day=myDate.getDate();       //获取当前日(1-31)

	 if(parseFloat(month)<10){
	   document.getElementById('currentDate').value=year+"-0"+month+"-"+day;
	 }else{
	   document.getElementById('currentDate').value=year+"-"+month+"-"+day;
	 }
     
   }
   function computeNextbyDate(){
		var currentDate=document.getElementById('currentDate').value;
		var expecteDate=document.getElementById('expecteDate').innerHTML;
		var spaceDate=document.getElementById('spaceDate').value;
	 	var str="";
		if(currentDate!=null && currentDate!='' && currentDate!=0){
			if(spaceDate==''||spaceDate.length==0){
				document.getElementById('expecteDate').innerHTML=currentDate;
			}else{
			    var dateArray=currentDate.split('-');
				var totalMonth=parseFloat(dateArray[1])+parseFloat(spaceDate);
				var addYear=parseInt(totalMonth/12);
				var totalMonth=parseFloat(totalMonth)-parseFloat(addYear*12);
				var finalDate;				
				if(totalMonth==0){
				   finalDate=parseFloat(dateArray[0])+parseInt(addYear)-1+"-"+12+"-"+dateArray[2];
				}else if(totalMonth>=0&&totalMonth<10){
				   totalMonth="0"+totalMonth;
				   finalDate=parseFloat(dateArray[0])+parseInt(addYear)+"-"+totalMonth+"-"+dateArray[2];
				}else if(totalMonth>=10){
				   totalMonth=totalMonth;
				   finalDate=parseFloat(dateArray[0])+parseInt(addYear)+"-"+totalMonth+"-"+dateArray[2];
				}
				document.getElementById('expecteDate').innerHTML=finalDate;
			}
		}else{
			document.getElementById('expecteDate').innerHTML='';
		}
	}

   function CheckInputInt(oInput) { 
    if ('' != oInput.value.replace(/\d/g,'')) 
    {
     oInput.value = oInput.value.replace(/\D/g,''); 
    }
    if(parseInt(oInput.value)<0.1){
      oInput.value="";
    }
 }
  </SCRIPT>
 </HEAD>

 <BODY onload="loadDate();">
  当前系统日期:<INPUT TYPE="TEXT" NAME="currentDate" id="currentDate" style="width:100px;" value="" readonly/><p>
  间隔&nbsp;&nbsp;<INPUT TYPE="TEXT" NAME="spaceDate" id="spaceDate" value=""  style="width:50px;" onkeyup="CheckInputInt(this);" onblur="CheckInputInt(this);" onafterpaste="CheckInputInt(this);"/>&nbsp;月<p>
  <span id="getDate" style="cursor:hand;background-color:#FF9090;" onclick="computeNextbyDate();" >Go-></span>&nbsp;期望日期:<span id="expecteDate">&nbsp;</span>
 </BODY>
</HTML>

?

  相关解决方案