Time Conversion

  • + 0 comments

    My solution in JS

      var splitted = s.split(":")
        var time = splitted[splitted.length -1].substring(2)
        if(time == "PM") {
            var hour = parseInt(splitted[0])
            if(hour != "12") {
                hour = 12 + hour
            }
            return hour + ":" +splitted[1] +":" + splitted[2].substring(0,2)
        } else {
            if(splitted[0] == "12") {
                splitted[0] = "00"
            }
            return splitted[0] + ":" +splitted[1] +":" + splitted[2].substring(0,2)
        }