第一种:
function compareDate (date1, date2) {
var Date1 = new Date(date1);var Date2 = new Date(date2);
if(Date1.getTime() > Date2.getTime()){
console.log(1);
} else {
console.log(2);
}
};
compareDate('2018-10-10','2018-11-28');
第二种:
var a = new Date(2018, 7, 1);
var b = new Date(2018, 7, 2);
console.log(a > b); // false
var a = new Date('2018-07-01');
var b = new Date('2018-07-01');
console.log(a == b); // false
var a = new Date('2018-07-01').getTime();
var b = new Date('2018-07-01').getTime();
console.log(a == b); // true