#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_;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.