📜  如何比较日期js - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:55.933000             🧑  作者: Mango

代码示例6
const x = new Date('2013-05-22');
const y = new Date('2013-05-23');

// less than, greater than is fine:
console.log('x < y', x < y); // false
console.log('x > y', x > y); // false
console.log('x === y', x === y); // false, oops!

// anything involving '=' should use the '+' prefix
// it will then compare the dates' millisecond values
console.log('+x <= +y', +x <= +y); // true
console.log('+x >= +y', +x >= +y); // true
console.log('+x === +y', +x === +y); // true