Javascript 时间比较器

Javascript 时间比较器,javascript,jquery,asp.net,regex,Javascript,Jquery,Asp.net,Regex,我想验证时间开始和时间结束。时间格式如下:凌晨2:15:00我希望确保时间结束必须大于或等于时间开始 时间开始从DropDownListHourStart(1-12)和DropDownListMinuteStart(1-59)以及DropDownListSecondStart(00)和DropDownlistStampStart(AM-PM)获取时间 时间结束从DropDownListHourEnd(1-12)和DropDownListMinuteEnd(1-59)以及DropDownListS

我想验证时间开始和时间结束。时间格式如下:凌晨2:15:00我希望确保时间结束必须大于或等于时间开始

时间开始从DropDownListHourStart(1-12)和DropDownListMinuteStart(1-59)以及DropDownListSecondStart(00)和DropDownlistStampStart(AM-PM)获取时间

时间结束从DropDownListHourEnd(1-12)和DropDownListMinuteEnd(1-59)以及DropDownListSecondEnd(00)和dropdownlistampend(AM-PM)获取时间


我要检查“时间结束”是否等于或大于中的时间。你能告诉我任何时间的验证技术吗?无论是jQuery、JavaScript还是ASP.NET控件验证程序。谢谢。

假设日期相同:

function timeToSec(str)
{
  var h = Number(str.match(/^\d+/));
  if(str.indexOf("PM") != -1)
    h += 12;
  var m = Number(str.match(/^\d+:(\d+):/)[1]);
  var s = Number(str.match(/:(\d+)\s+[AP]M/)[1]);
  return (h * 60 + m) * 60 + s;
}
if(timeToSec(start) > timeToSec(end))
  alert("Oops");

var j=document.getElementById('DropDownListHourStart')。value+“:”+document.getElementById('DropDownListMinuteStart')。value+“:”+document.getElementById('DropDownListSecondStart')。value+“+document.getElementById('DropDownlistAdminStart')。value;
var d=document.getElementById('DropDownListHourEnd')。value+“:”+document.getElementById('DropDownListMinuteEnd')。value+“:”+document.getElementById('DropDownListSecondEnd')。value+“+document.getElementById('DropDownListMinuteEnd')。value;
如果(d>=j){
document.getElementById('your_label_id')。innerText=“时间结束必须大于或等于时间开始”;
}

您可以在JavaScript中将其作为字符串进行比较。无需comparevalidator
<script type="text/javascript" >
        var j = document.getElementById('DropDownListHourStart').value+":"+document.getElementById('DropDownListMinuteStart').value+":"+document.getElementById('DropDownListSecondStart').value+" "+document.getElementById('DropDownListAMPMStart').value;
        var d = document.getElementById('DropDownListHourEnd').value+":"+document.getElementById('DropDownListMinuteEnd').value+":"+document.getElementById('DropDownListSecondEnd').value+" "+document.getElementById('DropDownListAMPMEnd').value;

        if (d >= j) {
            document.getElementById('your_label_id').innerText = "the Time-End must be greater or equal to the Time-Start";
        }
        </script>