Quantcast
Channel: Detecting an "invalid date" Date instance in JavaScript - Stack Overflow
Viewing all articles
Browse latest Browse all 58

Answer by Dmytro Shevchenko for Detecting an "invalid date" Date instance in JavaScript

$
0
0

Nice solution! Included in my library of auxiliary functions, now it looks like this:

Object.isDate = function(obj) {
/// <summary>
/// Determines if the passed object is an instance of Date.
/// </summary>
/// <param name="obj">The object to test.</param>

    return Object.prototype.toString.call(obj) === '[object Date]';
}

Object.isValidDate = function(obj) {
/// <summary>
/// Determines if the passed object is a Date object, containing an actual date.
/// </summary>
/// <param name="obj">The object to test.</param>

    return Object.isDate(obj) && !isNaN(obj.getTime());
}

Viewing all articles
Browse latest Browse all 58


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>