How to parse in javascript locale date string to iso string for any format

34 views Asked by At

Let's say my default language in the browser is Ukrainian.

const dateStr = new Date().toLocaleString();
console.log(dateStr); //28.02.2024, 23:35:40 

Now I want to parse this dateStr back to Date;

const dateObj = new Date(dateStr);
// Invalid date

I know that I can use luxon.fromFormat for example, but then I should know the current string format for the locale. Is there way to pares any Locale String back to Date or ISO String?

0

There are 0 answers