Skip to content

Instantly share code, notes, and snippets.

@DimovskiD
Created December 7, 2022 15:31
Show Gist options
  • Save DimovskiD/015c55207ea8289edef5ec6ba69b1bc4 to your computer and use it in GitHub Desktop.
Save DimovskiD/015c55207ea8289edef5ec6ba69b1bc4 to your computer and use it in GitHub Desktop.
fun Long.formatTime(): String {
val seconds = ((this / 1000).toInt() % 60).doubleDigit()
val minutes = ((this / (1000 * 60) % 60).toInt()).doubleDigit()
val hours = ((this / (1000 * 60 * 60) % 24).toInt()).doubleDigit()
var result = "$hours:$minutes:$seconds"
if (result.startsWith("00")) result = result.substring(3)
return result
}
fun Int.doubleDigit(): String = if (this.toString().length == 1) "0$this"
else this.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment