Skip to content
Advertisement

Script works only on Chrome and Firefox Desktop, and not works on Safari and any mobile browser

I can’t understand why this script works only on Chrome and Firefox on Desktop, and not works on Safari Desktop and any mobile browser.

JavaScript

I’ve checked all the incompatibilities but I don’t seem to see any. Returned to me alloways NaN even if I use Number(...)

I just can’t understand.

Advertisement

Answer

Safari is a lot more strict on date formats.

I would suggest changing the format of your data string or manipulating it with Regex and so forth but it all gets a bit messy. One is assuming all your date data is going to be consistent?!

Example: https://codepen.io/alexpetergill/pen/39b775983b851e8fa14f1e548252d810

Just tested this on Big Sur / Safari 14

JavaScript

The output of parseDate() is loosely based on the ECMAScript specification https://262.ecma-international.org/11.0/#sec-date-time-string-format

ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 calendar date extended format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement