We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Pretty simple javascript solution. Just splitting the time into hours, mins and secs, checking if it's am or pm and adjusting the hours as needed, then rejoining
functiontimeConversion(s){// Write your code herelettime=s.slice(0,8).split(':')letampm=s.slice(8)if(ampm==='PM'&&time[0]!=='12'){time[0]=parseInt(time[0])+12}elseif(ampm==='AM'&&time[0]==='12'){time[0]='00'}returntime.join(':')}
Cookie support is required to access HackerRank
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 →
Pretty simple javascript solution. Just splitting the time into hours, mins and secs, checking if it's am or pm and adjusting the hours as needed, then rejoining