#JavaScript: ISO 8601 formatted string to Date

ECMAScript 5 includes new support for ISO 8601 dates. This means you’ll be able to create a new Date object using an ISO 8601 formatted string. However, only a few browsers (Firefox 3.5 and WebKit-based browsers) currently support the new ISO 8601 formatting, so you’ll still need to provide the conversion functionality for IE  8.

If you attempt to create a JavaScript Date with an ISO 8601 formatted string, you’ll get an invalid date error in IE 8. d = new Date(‘2010-10-20T07:32:12Z’);

Fortunately we have Google Closure Library. The next 2 lines of code will solve the problem in IE 8:

d = goog.date.fromIsoString(‘2010-10-20T07:32:12Z’).date_;