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

Answer by Saurabh Gupta for Detecting an "invalid date" Date instance in JavaScript

$
0
0

So I liked @Ask Clarke answer with little improvement by adding try catch block for dates which cannot go through var d = new Date(d) -

function checkIfDateNotValid(d) {
        try{
            var d = new Date(d);
            return !(d.getTime() === d.getTime()); //NAN is the only type which is not equal to itself.
        }catch (e){
            return true;
        }

    }

Viewing all articles
Browse latest Browse all 58

Trending Articles