var first = $('#startTime').val(); var second = $('#endTime').val(); var data1 = Date.parse(first.replace(/-/g, "/")); var data2 = Date.parse(second.replace(/-/g, "/")); var datadiff = data2-data1; var time = 31*24*60*60*1000; if(first.length>0 && second.length>0){ if(datadiff<0||datadiff>time){ alert("开始时间应小于结束时间并且间隔小于31天,请检查!"); return false; } }