js比较日期大小

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/farxix/article/details/88058723
//获取当前时间
var currentTime = new Date();

//自定义时间
var customTime="2019-03-01 00:00:00";  
customTime= customTime.replace("-","/");//替换字符,变成标准格式  
customTime= new Date(Date.parse(customTime));

if(currentTime < customTime){
	alert("当前时间小于自定义时间");
}


var oDate1 = new Date('2019-03-01');
var oDate2 = new Date('2019-03-01');
if(oDate1 > oDate2){
        console.log('第一个大');
} else {
        console.log('第二个大');
}

猜你喜欢

转载自blog.csdn.net/farxix/article/details/88058723