Do not use the Date object to parse date strings, it is specified as implementation dependent in ECMAScript ed 3 and doesn't work consistently across browsers. One format of ISO8601 date string is specified in ES5, but that doesn't work consistently either. Manually parse the string.
A couple of functions to convert to and from UTC ISO8601 strings:
if (!Date.prototype.toUTCISOString) {
Date.prototype.toUTCISOString = function() {
function addZ(n) {
return (n<10? '0' : '') + n;
}
function addZ2(n) {
return (n<10? '00' : n<100? '0' : '') + n;
}
return this.getUTCFullYear() + '-' +
addZ(this.getUTCMonth() + 1) + '-' +
addZ(this.getUTCDate()) + 'T' +
addZ(this.getUTCHours()) + ':' +
addZ(this.getUTCMinutes()) + ':' +
addZ(this.getUTCSeconds()) + '.' +
addZ2(this.getUTCMilliseconds()) + 'Z';
}
}
if (!Date.parseUTCISOString) {
Date.parseUTCISOString = function fromUTCISOString(s) {
var b = s.split(/[-T:\.Z]/i);
var n= new Date(Date.UTC(b[0],b[1]-1,b[2],b[3],b[4],b[5]));
return n;
}
}
var s = '2012-05-21T14:32:12Z'
var d = Date.parseUTCISOString(s);
alert('Original string: ' + s +
'\nEquivalent local time: ' + d +
'\nBack to UTC string: ' + d.toUTCISOString());