You are viewing a single comment's thread. Return to all comments →
My solution in js:
function timeConversion(s) { const isMorning = s.includes("A") || false const timeArr = s.split(":") let hour = parseInt(timeArr[0]) let min = parseInt(timeArr[1]) min = min < 10 ? `0${min}` : `${min}` let sec = parseInt(timeArr[2].replace(/[^0-9]/gi, '')) sec = sec < 10 ? `0${sec}` : `${sec}` if (isMorning) { if (hour === 12) { return `00:${min}:${sec}` } else { hour = hour < 10 ? `0${hour}` : `${hour}` return `${hour}:${min}:${sec}` } } else { if (hour === 12) { return `${hour}:${min}:${sec}` } else { return `${hour + 12}:${min}:${sec}` } } }
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 →
My solution in js: