12시간 AM/PM 시간 형식을 24시간 시간 형식으로 변환하는 문제.
s = '12:01:00PM'
Return '12:01:00'
s = '12:01:00AM'
Return '00:01:00'
s = '07:05:45PM'
Return '19:05:45'
function timeConversion(s) {
const beforeArr = s.split(":");
const beforeHour = Number(beforeArr[0]);
let afterHour = "0" + beforeHour ;
if(beforeHour < 12 && beforeArr[2].slice(2,4) === "PM") {
afterHour = 0;
afterHour = beforeHour + 12 + "";
}
if(beforeHour === 12 && beforeArr[2].slice(2,4) === "AM") {
afterHour = 0;
afterHour += "0";
}
if(beforeHour === 12 && beforeArr[2].slice(2,4) === "PM") {
afterHour = 12;
}
const afterSec = beforeArr[2].slice(0,2);
const afterArr = [afterHour, beforeArr[1], afterSec];
let string = afterArr.join(":");
return string;
}