Created
April 22, 2019 04:32
-
-
Save whoisryosuke/5058b3f0197f0e19ea7039c922529f15 to your computer and use it in GitHub Desktop.
JS - Compare date and time - via: https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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