js时间大小判断写法demo

//和当前日期进行比较 

function editReport(reportId,time1) {
    var myDate = new Date();
    var time2;
    time2 = myDate.getFullYear().toString()+"-"+(myDate.getMonth()+1).toString()+"-"+myDate.getDate().toString();
    var d1 = new Date(time1.replace(/-/g,"/")); 
    var d2 = new Date(time2.replace(/-/g,"/"));     
    if(Date.parse(d2) > Date.parse(d1)){
      alert("超过阶段上报日期,禁止上报!");
    }else {
       var reportId = reportId; 
       reportForm.action="editReport.action?reportId="+reportId;
       reportForm.submit();
    }  
  }

//获取界面时间进行比较

  var issuedDate1=document.getElementById("issuedDate_s1").value;
  var issuedDate2=document.getElementById("issuedDate_s2").value;

  if(issuedDate1.length>0&&issuedDate2.length>0){
    if(Date.parse(issuedDate1.replace("-", "/")) > Date.parse(issuedDate2.replace("-", "/"))){
        alert("开始时间不能大于结束时间!");
       return;
     }
  }

 

 

 

posted @ 2012-11-26 17:02  冰镇橘子汽水  阅读(608)  评论(0编辑  收藏  举报