hour Of Am Pm
The 12-hour (1..12) time component.
See also
Throws
during assignment if the value is outside the 0..99
range.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Formatting and parsing a time with AM/PM marker in complex scenarios
val format = DateTimeComponents.Format {
amPmHour(); char(':'); minute(); char(':'); second(); char('.'); secondFraction(1, 9)
char(' '); amPmMarker("AM", "PM")
}
val formattedTime = format.format {
setTime(LocalTime(3, 46, 58, 123_456_789))
check(hour == 3)
check(minute == 46)
check(second == 58)
check(nanosecond == 123_456_789)
check(hourOfAmPm == 3)
check(amPm == AmPmMarker.AM)
}
check(formattedTime == "03:46:58.123456789 AM")
val parsedTime = format.parse("03:46:58.123456789 AM")
check(parsedTime.toLocalTime() == LocalTime(3, 46, 58, 123_456_789))
check(parsedTime.hour == null)
check(parsedTime.minute == 46)
check(parsedTime.second == 58)
check(parsedTime.nanosecond == 123_456_789)
check(parsedTime.hourOfAmPm == 3)
check(parsedTime.amPm == AmPmMarker.AM)
//sampleEnd
}