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

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

$
0
0

Instead of using new Date() you should use:

var timestamp = Date.parse('foo');

if (isNaN(timestamp) == false) {
  var d = new Date(timestamp);
}

Date.parse() returns a timestamp, an integer representing the number of milliseconds since 01/Jan/1970. It will return NaN if it cannot parse the supplied date string.


Viewing all articles
Browse latest Browse all 58

Latest Images

Trending Articles



Latest Images

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