Dates on iOS

My code below works fine on PC Chrome but not on Chrome on iOS

const convertedLocalTimeString = convertedLocalTime.toLocaleString();
 console.log(`Visitor local time ${visitorLocalTimeString} and converted local time ${convertedLocalTimeString}`);
const convertedTime = new Date(convertedLocalTimeString);
console.log(`converted time ${convertedTime}`) //invalid date on console

Is there a reason why this doesnt work on iOS?

Out of curiosity, does it work in Safari?

I only ask because Chrome on iOS is different than Chrome anywhere else. Apple forces the webKit rendering engine on all browsers when run in iOS, and though I’ve seen some indications that the javascript engine is the same across the versions of Chrome, I’ve also seen some that say iOS requires the same javascript engine for all browsers like they do the rendering engine.

1 Like

no it doesn’t work on Safari

I do almost zero date work on iOS, but looks like the date format is the killer.

Try this

const convertedTime = new Date(convertedLocalTimeString.replace(/-/g, "/"));

Source: https://stackoverflow.com/questions/4310953/invalid-date-in-safari

Are you sure this will give you the expected result? As normally dates with “-” are formatted day-month-year while dates with “/” are formatted as month/day/year

Nope. Hence why I cited the source…it looks to be a javascript engine problem, so I googled it.

This seems to be working

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.