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.
- Prepare
- Algorithms
- Warmup
- Time Conversion
- Discussions
Time Conversion
Time Conversion
Sort by
recency
|
5088 Discussions
|
Please Login in order to post a comment
function timeConversion(s) { // Write your code here // take the 12-hour-format AM or PM let timeFormat = s.slice(-2) let hourHand = s.slice(0,2) let minuteHand = s.slice(3,5) let secondsHand = s.slice(6,8) if(timeFormat == "AM" && hourHand == '12'){ let militaryHourHand = Number(hourHand)-12 return
0
{minuteHand}:${secondsHand}
} else if(timeFormat == 'PM'){ if(hourHand == '01' || hourHand == '02' || hourHand == '03' || hourHand == '04' || hourHand == '05' || hourHand == '06' || hourHand == '07' || hourHand == '01' || hourHand == '08' ||hourHand == '09' || hourHand == '10' || hourHand == '11'){ let militaryHourHand = Number(hourHand) + 12 return${militaryHourHand}:$`{minuteHand}:${secondsHand}` } else { return
{minuteHand}:${secondsHand}
}} else { return
{minuteHand}:${secondsHand}
}}
Another C# Solution
Here is my c++ solution, you can watch the vidéo here : https://youtu.be/G7bia__Vxqg