Time Conversion Solution in Kotlin — HackerRank

07:05:45PM
19:05:45

fun timeConversion(s: String): String {
/*
* Write your code here.
*/
val getZone = s.substring(8, 10)
val getTime = s.substring(0, 8)
val getHour = s.substring(0, 2)
val getMinutes = s.substring(2, 8)
var result: String
if (getZone == "AM") {
result = if (getHour == "12") "00$getMinutes" else getTime
} else {
var sum = getHour.toInt() + 12
result = if (getHour == "12") getTime else "$sum$getMinutes"
}
return result
}

--

--

--

Hey curious person, I am Software Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a Design System implementation using Jetpack Compose — Part2

Barista UI Testing(on top of Espresso)

Android Better Logging using Timber Library

Modular Navigation with Jetpack Compose

Apple and Orange Solution in Kotlin -HackerRank

Haunting Story: buildOutput.apkData must not be null

How We Handled a Large-scale AndroidX Migration

Publishing PWA as Native app on Google Play Store with FCM Notifications via TWA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Umar Syaid Himawan

Umar Syaid Himawan

Hey curious person, I am Software Developer

More from Medium

Java 102 : Executor Service in concurrent Package.

COMPARISON BETWEEN INHERITANCE AND POLYMORPHISM

Lifecycle awareness

compileOnly and runtimeOnly, My experiment with them.