我有两个从下拉框中选择的时间值。时间格式为hh:mm am/pm
。我需要比较这两个日期。我已经完成了这段代码,但它对我不起作用。
<select id="eventstarttime">
<option>10:00am</option>
........
<option>3:00pm</option>
</select>
<select id="eventstoptime" onblur="return checktime()">
<option>10:00am</option>
........
<option>3:00pm</option>
</select>
javascript方法是
function checktime()
{
var start = document.getElementById("eventstarttime").value;
var end = document.getElementById("eventstoptime").value;
if(Date.parse('01/01/2011 '+end) < Date.parse('01/01/2011 '+start))
{
alert("End time should exceed the start time");
}
else if(Date.parse('01/01/2011 '+end) -Date.parse('01/01/2011 '+start)==0)
{
alert("Start time and end time cannot be same");
}
return false;
}