If you want to compare two dates, the Date object will do the following purpose. This describes the JavaScript Date Object including properties, constructors, and methods.
Here is the code example :-
var d1 = new Date();
var d2 = new Date(d1);
var Equalcomp = d1.getTime() === d2.getTime();
var notEqualcomp = d1.getTime() !== d2.getTime();
For ==, !=, === comparison you need to use the getTime() method otherwise it will not return the correct value.
for example :-
var d1 = new Date();
var d2 = new Date(d1);
console.log(d1 === d2); // prints false
console.log(d1 != d2); // prints true
The above code snippet will return the wrong answer values. Therefore, you need to use getTime() method for this.
0 Comment(s)