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

>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)

Leave a Reply