<script>
//比较时间 格式 yyyy-mm-dd hh:mi:ss
window.οnlοad=function() {
var beginTime = '2011-01-01 00:00:00';
var endTime = '2011-01-01 00:00:01';
var beginTimes=beginTime.substring(0,10).split('-');
var endTimes=endTime.substring(0,10).split('-');
beginTime=beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19);
endTime=endTimes[1]+'-'+endTimes[2]+'-'+endTimes[0]+' '+endTime.substring(10,19);
var disparityTime =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
var disparityTime =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
if(disparityTime<0){
alert("开始时间大");
}else if (disparityTime>0){
alert("结束时间大");
}else if (disparityTime==0){
alert("相等");
}else{
return "格式不对";
}
}
</script>
注:不知何故,firefox对于类似“2010-12-20 15:55:00”这种时间的转换格式不感冒,返回Nan,查了查资料,把“-”替换为“/”就可以了;