My input is get via an API, and I have this array with the following date format as strings:"2022-06-29T15:30:00 00:00", "2022-07-01T09:00:00 00:00", "2022-07-05T16:00:00 00:00".
I want to transform those date in another format (ex for the first one: 29.06.2022 (DD.MM.YYYY)).
Also, I want to compare dates to sort the array. How can I do this? Do I need to convert it into a Date object? (vanilla JS, no frameworks).
CodePudding user response:
You can consider doing it like this:
const str = "2022-06-29T15:30:00 00:00";
const date = new Date(Date.parse(str));
console.log(date); //