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

Identify And Block Phone Calls From Spammers And Unwanted Numbers

block phone calls, win PayPal prepaid card, gift card, Call App

How to Open Full Play Store on Google TV

How to Open Full Play Store on Google TV

Instagram Data Saver Mode

Running Unity game on real Android device

An Overview of the Android Platform Architecture

Soft UI (Neomorphism) design in Android

Introduction to the Dependency Injection

Android Architecture Pattern

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

Coroutine Adventure Part.4

Better way of binding different data with similar properties in viewholder using sealed class

Common Gotchas in Android’s Share Sheet

Learn Kotlin -Null Safety