So I have a time array which holds slot time. I am trying to convert 12 hr format to 24 hr format but it is not working
Here is what I have tried so far:
let timeArray = ["11:12 AM", "11:13 AM", "1:14 PM"];
for (i in timeArray) {
let [time, mod] = timeArray[i].split(" ");
let [hr, min] = time.split(":");
if (hr < 12) {
hr = hr + 12;
}
console.log(hr);
}
Here is the output:
The expected output should add 12 to hr number to convert it to 24 hr format.