js 日期比较大小

function checkDate(){
   var startTime=document.getElementById("startTime").value; //获得系统日期的文本值
   var endTime=document.getElementById("endTime").value; //获得用户选择的日期文本值
   var aStart=startTime.split('-'); //转成成数组,分别为年,月,日,下同
   var aEnd=endTime.split('-');
   var startDate = aStart[0]+"/" + aStart[1]+ "/" + aStart[2];
   var endDate = aEnd[0] + "/" + aEnd[1] + "/" + aEnd[2];
   if (startDate > endDate) {
    $("#moneyMessage").html("<font color=red>开始日期必须小于结束日期</font>");
    return false;
   }
    return true;
  }


 

 

<script language="javascript" type="text/javascript">
        function DataCompare() {
            
            var bgTime = document.getElementById("txtBeginTime").value;
            var edTime = document.getElementById("txtEndTime").value;

            var beginTimeArray = bgTime.split("-");
            var endTimeArray = edTime.split("-");

            var beginTime = beginTimeArray[0] + "/" + beginTimeArray[1] + "/" + beginTimeArray[2];
            var endTime = endTimeArray[0] + "/" + endTimeArray[1] + "/" + endTimeArray[2];
            
            if(beginTime>endTime) {
                window.alert("起始时间要小于结束时间!");
                return false;
            }
            return true;
     }
        
    </script>


 

 

 

你可能感兴趣的:(JavaScript,function)