hour

abstract fun hour(padding: Padding = Padding.ZERO)(source)

The hour of the day, from 0 to 23.

By default, it's zero-padded to two digits, but this can be changed with padding.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Defining a custom format for the local time
// format the local time as a single number
val format = LocalTime.Format {
    hour(); minute(); second()
    optional { char('.'); secondFraction(1, 9) }
}
val formatted = format.format(LocalTime(9, 34, 58, 120_000_000))
check(formatted == "093458.12") 
   //sampleEnd
}