user2054381
user2054381

Reputation:

In Javascript verify is var is valid datetime object

I need to verify is var is valid datetime object. This

alert( "dat::"+( typeof dat ))

returns "object". Which is the valid way ?

Upvotes: 0

Views: 72

Answers (2)

Ehsan
Ehsan

Reputation: 4474

Here is how I would do it:

if ( Object.prototype.toString.call(d) === "[object Date]" ) {
  // it is a date
}
else {
  // not a date
}

Upvotes: 2

Scimonster
Scimonster

Reputation: 33409

Use instanceof:

dat instanceof Date

Upvotes: 1

Related Questions