计算两个时间的时间差
function GetDateDiff(startTime, endTime, diffType) {
//将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式
startTime = startTime.replace(/\-/g, "/");
endTime = endTime.replace(/\-/g, "/");
//将计算间隔类性字符转换为小写
diffType = diffType.toLowerCase();
var sTime =new Date(startTime); //开始时间
var eTime =new Date(endTime); //结束时间
//作为除数的数字
var timeType =1;
switch (diffType) {
case"second":
timeType =1000;
break;
case"minute":
timeType =1000*60;
break;
case"hour":
timeType =1000*3600;
break;
case"day":
timeType =1000*3600*24;
break;
default:
break;
}
return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(timeType));
}
//计算两个日期之间相差的分钟
console.log(GetDateDiff("2016-03-28 10:30:22","2016-03-28 10:38:00","minute"));
//转化为毫秒数比价大小就行了
var d_1 = "2014-11-22";
var d_2 = "2014-11-22";
//比较两个日期的先后
console.log(dd(d_1,d_2))
function dd(d_1,d_2){
var e_1 = new Date(d_1).getTime();
var e_2 = new Date(d_2).getTime();
if(e_1>e_2){
return true;
}else{
return false;
}
}