Home  >  Article  >  php教程  >  js 时间大小比较

js 时间大小比较

WBOY
WBOYOriginal
2016-06-07 11:37:051481browse

js 时间大小比较,一般用户前端比较选择的2个时间大小。
//js 时间大小比较
function dateCompare(start_time,end_tile){
start_time = start_time.replace(/\-/gi,"/");
end_tile = end_tile.replace(/\-/gi,"/");
var time1 = new Date(start_time).getTime();
var time2 = new Date(end_tile).getTime();
//开始时间大于结束时间
if(time1 > time2){
return 1;
}else if(time1 == time2){
//开始时间=结束时间
return 2;
}else{
//开始时间小于结束时间
return 3;
}

}

用法:
1,把代码放到界面能调用到的地方
2,
//开始时间不能大于结束时间
if(dateCompare(start_time,end_time) == 1){
alert('开始时间不能大于结束时间');
return;
}

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn