Possible Duplicate:
Detecting an “invalid date” Date instance in JavaScript
Is there is a function IsDate() in javascript?
Possible Duplicate:
Detecting an “invalid date” Date instance in JavaScript
Is there is a function IsDate() in javascript?
Try this:
var date = new Date(); console.log(date instanceof Date && !isNaN(date.valueOf())); This should return true.
UPDATED: Added isNaN check to handle the case commented by Julian H. Lam
new Date('derp') instanceof Date // truenew Date('Test 1') evaluates to the same as new Date('1'). The only way to get it working correctly would be either to develop your own string parsing, or you could use date-fns.org - the isValid() function seems to work correctly.