Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created April 22, 2019 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoisryosuke/5058b3f0197f0e19ea7039c922529f15 to your computer and use it in GitHub Desktop.
Save whoisryosuke/5058b3f0197f0e19ea7039c922529f15 to your computer and use it in GitHub Desktop.
// Direct comparison (did it happen now?)
var d1 = new Date();
var d2 = new Date(d1);
console.log(d1 == d2); // prints false (wrong!)
console.log(d1 === d2); // prints false (wrong!)
console.log(d1 != d2); // prints true (wrong!)
console.log(d1 !== d2); // prints true (wrong!)
console.log(d1.getTime() === d2.getTime()); // prints true (correct)
// >= / <= Greater than or equal to
var oDateOne = new Date();
var oDateTwo = new Date();
alert(oDateOne - oDateTwo === 0);
alert(oDateOne - oDateTwo < 0);
alert(oDateOne - oDateTwo > 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment