How does safari convert the 2019-01-07T14:40:47.000+0000 type of time format?

Jun.15,2022

use moment


this is the standard ISO-8601 format.
just so new Date ("2019-01-07T14:40:47.000+0000") is fine.


Congratulations on stepping into an old pit. Safari does not support the format 2019-01-07 . You just need to replace - with / , that is, 2019-01-07 .


the simplest thing is to use moment.js or consider extracting the code from moment.js.
this is a bit crude, but simply extract the year, month, day, time, minute and second according to the position of T and then calculate the time difference

function formatUTC(t) {
  if(t.indexOf('T')!=-1){
     var y,h; //,
      var regH = /(T| )(\d\d:\d\d:\d\d)(\.\d+)?/;// 
      h = t.match(regH);
      h = h&&h[2]; //
      y = t.slice(0,t.indexOf('T')+1); //
      var timestamp = new Date(Date.parse(y.slice(0,-1)+' '+h)).getTime() / 1000;
      off = new Date().getTimezoneOffset() / 60; //
      timestamp -= off * 60 * 60;
     return new Date(parseInt(timestamp) * 1000);
  } 
 return new Date(t.replace(/\-/g,'/'));
}

formatUTC("2019-01-07T14:40:47.000+0000");
Menu