Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid date for Safari and IE fixed but not with negative UTC

I saw a lot of answers for the date problem with Safari and IE for the date, using replace(/-/g, "/") works like a charm for these cases 2022-11-30 17:00 UTC+0200 but encountered an issue when I had other time zone like this one 2022-11-28 21:56 UTC-0500 it would create an invalid date again, for any browser.

So I’m looking for a solution that would replace the "-" not globally but only in the first word eventually.

Thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What about that?

const date = `2022-11-30 17:00 UTC-0200`
const regex = /(\d+)-(\d+)-(\d+)/g
const result = date.replace(regex, '$1/$2/$3')
console.log(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading