for example, is there a correct way? please give me some advice
.
for example, is there a correct way? please give me some advice
.
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");
safari: reference article nginx configuration ...
to reflect the effect, 1.js is a large file. <body> Hello <script src="1.js" defer> < script> < body> after visiting the page, you should immediately display "Hello ", and then continue to load js, in the background,...
when the recent official account project opens the return button on ios, the page flashes and looks it up on the Internet because ios kernel browsers have BF cache, but use it window.addEventListener( pageshow ,function (e) { if (e.persisted) { ...