Is there a way to check if a variable is a Date in JavaScript? [duplicate]

Solution 1:

Use instanceof

(myvar instanceof Date) // returns true or false

Solution 2:

Object.prototype.toString.call(obj) === "[object Date]" will work in every case, and obj instanceof Date will only work in date objects from the same view instance (window).