javascript date.parse difference in chrome and other browsers javascript date.parse difference in chrome and other browsers javascript javascript

javascript date.parse difference in chrome and other browsers


Here is a fix for Firefox and IE/Safari (with the help from JavaScript: Which browsers support parsing of ISO-8601 Date String with Date.parse ) :

DEMO

var noOffset = function(s) {  var day= s.slice(0,-5).split(/\D/).map(function(itm){    return parseInt(itm, 10) || 0;  });  day[1]-= 1;  day= new Date(Date.UTC.apply(Date, day));    var offsetString = s.slice(-5)  var offset = parseInt(offsetString,10)/100;  if (offsetString.slice(0,1)=="+") offset*=-1;  day.setHours(day.getHours()+offset);  return day.getTime();}

From MDN

JavaScript 1.8.5 note

A subset of ISO 8601 formatted date strings can now also be parsed.

Alternatively, the date/time string may be in ISO 8601 format. Starting with JavaScript 1.8.5 / Firefox 4, a subset of ISO 8601 is supported. For example, "2011-10-10" (just date) or "2011-10-10T14:48:00 (date and time) can be passed and parsed. Timezones in ISO dates are not yet supported, so e.g. "2011-10-10T14:48:00+0200" (with timezone) does not give the intended result yet.