日期:2014-05-16  浏览次数:20437 次

js比较格式yyyy-mm-dd hh:mm:ss类型的时间的大小

<script>
//比较时间 格式 yyyy-mm-dd hh:mi:ss??

window.onload=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>