You are viewing a single comment's thread. Return to all comments →
That's my solution in javascript
function timeConversion(s) { const isPM = s.includes("PM"); const isMidnight = s.split(':')[0] == "12"; console.log(isMidnight); if(!isPM && isMidnight){ const midnight = s.split(':'); midnight[0] = "00" return midnight.join(":").replace("AM",""); }else if(!isPM){ return s.replace("AM",""); }else{ const hourArr = s.replace("PM","").split(":").map(i => Number(i)); hourArr[0] += 12; hourArr[0] == 24? hourArr[0] = 12: hourArr[0]=hourArr[0]; return hourArr.map(i => { if (i >=0 && i < 10){ return String( "0" + i) }else{ return String(i) } }).join(":") } }
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
That's my solution in javascript