Time Conversion

  • + 0 comments

    import java.io.* import java.math.* import java.security.* import java.text.* import java.util.* import java.util.concurrent.* import java.util.function.* import java.util.regex.* import java.util.stream.* import kotlin.collections.* import kotlin.comparisons.* import kotlin.io.* import kotlin.jvm.* import kotlin.jvm.functions.* import kotlin.jvm.internal.* import kotlin.ranges.* import kotlin.sequences.* import kotlin.text.*

    /* * Complete the 'timeConversion' function below. * * The function is expected to return a STRING. * The function accepts STRING s as parameter. */

    fun timeConversion(s: String): String { var ret ="" // Write your code here if(s.contains("PM")){ var time = s.split(":")

          var cal = time[0].toInt()
          if(cal<12){
            cal = cal+12
          }
    
          var calctime = cal.toString()+":"+time[1]+":"+time[2]
            var calctimewithoutPm = calctime.split("PM")
    ret = calctimewithoutPm[0].toString()
    

    } else{ var timeWithoutAm = s.split("AM") var cal =timeWithoutAm[0] var time =cal.toString().split(":") var zero = time[0] if(time[0].toInt()>=12){ zero = ((zero.toInt())-12).toString() if(zero.toInt()==0){ zero="00" } }

      var calctime = zero.toString()+":"+time[1]+":"+time[2]
           // var calctimewithoutPm = calctime.split("PM")
            ret = calctime
    

    } return ret }

    fun main(args: Array) { val s = readLine()!!

    val result = timeConversion(s)
    
    println(result)
    

    }