You are viewing a single comment's thread. Return to all comments →
Scala
def timeConversion(s: String): String = { // Write your code here val isAM = if(s.toUpperCase().contains("AM")) true else false val timeArray = s.split(":") val hours = timeArray(0) val minutes = timeArray(1) val seconds = timeArray(2) val militaryTime: String = hours match { case "12" if(isAM) => s"00:${minutes}:${seconds}" case "12" => s"12:${minutes}:${seconds}" case s if(!isAM) => s"${(Integer.parseInt(hours) + 12)}:${minutes}:${seconds}" case _ => s } militaryTime.replace("PM","").replace("AM", "") }
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 →
Scala