Little things about JS Date
Safari invalid date
Used the same code in safari, firefox and chrome and got different results.
code:js
new Date('2021-10-11 10:00:00')
// Worked in Chrome and firefox safari but got 'Invalid Date' from safari.
Reason
The correct time format JS follow by is ISO 8601 calendar date extended format, which looks like this:
YYYY-MM-DDTHH:mm:ss.sssZ
for example 2021-12-06T01:10:10.21Z
About the 'T'
the "T" appears literally in the string, to indicate the beginning of the time element.
About the 'Z'
is the UTC offset representation specified as "Z" (for UTC with no offset) or an offset of either "+" or "-" followed by a time expression HH:mm (indicating local time ahead of or behind UTC, respectively)
Chrome and Firefox, which can handle formats other than this format, actually help us do some more processing. Safari did not do this processing, so it reported an error.
Salution
Option1.
Option2. (not recommend)
Thought it's not a correct format, Safari can handle the 2021/10/11 10:00:00 format and turn it into a Date Object.
code:javascript
new Date('2021-10-11 10:00:00'.replace(/-/g, "/"))