amPmHour

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

The hour of the day in the 12-hour clock:

  • Midnight is 12,

  • Hours 1-11 are 1-11,

  • Noon is 12,

  • Hours 13-23 are 1-11.

To disambiguate between the first and the second halves of the day, amPmMarker should be used.

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

See also

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Defining a custom format for the local time that uses AM/PM markers
val format = LocalTime.Format {
    amPmHour(); char(':'); minute(); char(':'); second()
    char(' '); amPmMarker("AM", "PM")
}
val formatted = format.format(LocalTime(9, 34, 58, 120_000_000))
check(formatted == "09:34:58 AM") 
   //sampleEnd
}