I am getting a time format, which is the following 2022-12-24T16:00:00Z
and I want to convert it to a timestamp, I found a format, but it only works by removing the letters "T" and "Z" that are embedded inside the time. Which doesn't work for me, because I get it automatically, and my intention is that's how I get it, automatically convert it to timestamp
const str = "2022-12-24T16:00:00Z";
const [dateComponents, timeComponents] = str.split(" ");
console.log(dateComponents); // ️
console.log(timeComponents); // ️
const [year, month, day] = dateComponents.split("-");
const [hours, minutes, seconds] = timeComponents.split(":");
const date = new Date(+year, month - 1, +day, +hours, +minutes, +seconds);
console.log(date); // ️
// ✅ Get timestamp
const timestamp = date.getTime();
console.log(timestamp); // ️
How could it be solved, without having to enter it without those letters within the time
convert data to timestamp, but this data has a different format, which if you remove the excess, it works, but if not, no.