Time Conversion

  • + 0 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

    function timeConversion(s) {
        // Write your code here
        let time = s.slice(0, 8).split(':')
        let ampm = s.slice(8)
        if(ampm === 'PM' && time[0] !== '12'){
            time[0] = parseInt(time[0]) + 12
        } else if(ampm === 'AM' && time[0] === '12'){
            time[0] = '00'
        }
        return time.join(':')
        
    
    }