欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js 比较时间大小

程序员文章站 2022-06-21 12:30:04
...

var beginTime = "2009-09-21 00:00:00";
var endTime = "2009-09-21 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);

alert(beginTime+"aaa"+endTime);
alert(Date.parse(endTime));
alert(Date.parse(beginTime));

var a =(Date.parse(endTime)-Date.parse(beginTime))/3600/1000;
if(a<0){
alert("endTime小!");
}else if (a>0){
alert("endTime大!");
}else if (a==0){
alert("时间相等!");
}else{
return 'exception'}
}

本文转载自:http://zkliqiang.iteye.com/blog/965150
相关标签: js