//+-------------------------------------------------- //| 校验开始日期和结束日期 //+-------------------------------------------------- function vali_Date() { var start = $("#startDate").val(); var end = $("#endDate").val(); if($("#chooseDay").attr("checked") == "checked" || $('input:radio[name="conditionType"]:checked').val() == '2'){ if(!stringIsNull(start) && !stringIsNull(end)){ alert('请选择时间'); $("#startDate").focus(); return false; } else if(!stringIsNull(start)){ alert('请选择开始时间'); $("#startDate").focus(); return false; } else if(!stringIsNull(end)){ alert('请选择结束时间'); $("#endDate").focus(); return false; } } if(stringIsNull(start) && stringIsNull(end)){ if(end<start){ alert('结束时间不能小于开始时间!'); $("#endDate").focus(); return false; } var d = new Date(); var sysdate = d.toLocaleDateString(); sysdate = Date.parse(sysdate);//系统当前时间 var endDate = Date.parse(end); if(endDate>sysdate || endDate==sysdate){ alert('结束时间不能大于等于系统当前时间!'); $("#endDate").focus(); return false; } var days = daysBetween(start,end); if(days>180){ alert('时间跨度不能超过六个月!'); $("#endDate").focus(); return false; } } return true; } //+-------------------------------------------------- //| 求两个时间的天数差 日期格式为 YYYY-MM-dd //+-------------------------------------------------- function daysBetween(DateOne,DateTwo) { var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-')); var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1); var OneYear = DateOne.substring(0,DateOne.indexOf ('-')); var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-')); var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1); var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-')); var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000); return Math.abs(cha); }
详细解决方案
校验开始日期跟结束日期
热度:336 发布时间:2012-08-24 10:00:20.0
相关解决方案