function setDate()
  {
         if(window.document.all.text1.value.toString().length==0
            || window.document.all.text2.value.toString().length==0)
         {
            reutn false;
         }
         else
         {
           var date=new Date(window.document.all.text1.value);
  var year=date.getFullYear();
  var month=date.getMonth();
  var day=date.getDate();
  day=Math.abs(day)+Math.abs(window.document.all.text2.value);
  var newDate=new Date(year,month,day);

  //格式代输出日期
  var strDate="";
  year=newDate.getFullYear();
  month=Math.abs(newDate.getMonth())+1---因为javascript中月份从0开始;
  if(month.toString().length==1){month="0"+month.toString();}
  day=newDate.getDate();
  if(day.toString().length==1){day="0"+day.toString();}

  strDate=year+"-"+month+"-"+day;
  alert(strDate);
          }
  }
  其中text1为入境日期,text2为停留日期

解决方案 »

  1.   

    //[extended method] Date.toString by format string
    Date.prototype.Format = function(format) //author: meizz
    {
      var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "H+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
      }
      if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
      for(var k in o)if(new RegExp("("+ k +")").test(format))
        format = format.replace(RegExp.$1,
          RegExp.$1.length==1 ? o[k] : 
            ("00"+ o[k]).substr((""+ o[k]).length));
      return format;
    };var s = document.formName.textName.value;
    var n = Date.parse(s.replace(/-/g, "\/"));
    if(!isNaN(n))
    {
      n += days * 24 * 60 * 60 * 1000;
      var d = new Date(n);
      alert(d.Format("yyyy-MM-dd"));
    }
      

  2.   

    javascript中不支持d.Format("yyyy-MM-dd")这种方法;
      

  3.   

    <script>
      function getLeaDate(arrDate,dnum){
         var dt=new Date(arrDate.replace(/-/g,"/"));
     dt.setDate(dt.getDate()+dnum);
     return dt.getFullYear()+"-"+(dt.getMonth()+1)+"-"+dt.getDate();
      }
      alert(getLeaDate("2005-3-21",74))
    </script>
      

  4.   

    javascript中不支持d.Format("yyyy-MM-dd")这种方法;
    我上面不是有一段代码对 Date 对象添加成员函数 Format() 吗??