Does Javascript/EcmaScript3 support ISO8601 date parsing?

Alex Nolasco picture Alex Nolasco · Mar 19, 2010 · Viewed 9.8k times · Source

How are you currently parsing ISO8601 dates e.g. 2010-02-23T23:04:48Z in JavaScript?

Some browsers return NaN (including Chrome) when using the code below, FF3.6+ works though.

<html>
<body>
  <script type="text/javascript">
  var d = Date.parse("2010-02-23T23:04:48Z");
  document.write(d);
</script>
</body>
</html>

You can try this here http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_parse

Answer

sandstrom picture sandstrom · Jul 20, 2011

This is an excellent implementation which covers edge cases and falls back to native implementation. https://github.com/csnover/js-iso8601/