Format

Creates a new format for parsing and formatting LocalTime values.

Example:

LocalTime.Format {
hour(); char(':'); minute(); char(':'); second()
optional { char('.'); secondFraction() }
}

Only parsing and formatting of well-formed values is supported. If the input does not fit the boundaries (for example, second is 60), consider using DateTimeComponents.Format instead.

There is a collection of predefined formats in LocalTime.Formats.

Throws

if parsing using this format is ambiguous.

Samples

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

fun main() { 
   //sampleStart 
   // Parsing and formatting LocalTime values using a custom format
val customFormat = LocalTime.Format {
    hour(); char(':'); minute(); char(':'); second()
    char(','); secondFraction(fixedLength = 3)
}
val time = LocalTime(8, 30, 15, 123_456_789)
check(time.format(customFormat) == "08:30:15,123")
check(time.format(LocalTime.Formats.ISO) == "08:30:15.123456789") 
   //sampleEnd
}