Format
actual fun Format(block: DateTimeFormatBuilder.WithUtcOffset.() -> Unit): DateTimeFormat<UtcOffset>(source)
expect fun Format(block: DateTimeFormatBuilder.WithUtcOffset.() -> Unit): DateTimeFormat<UtcOffset>(source)
Creates a new format for parsing and formatting UtcOffset values.
Since UtcOffset values are rarely formatted and parsed on their own, instances of DateTimeFormat obtained here will likely need to be passed to DateTimeFormatBuilder.WithUtcOffset.offset in a format builder for a larger data structure.
There is a collection of predefined formats in UtcOffset.Formats.
Throws
if parsing using this format is ambiguous.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Parsing a UtcOffset using a custom format
val customFormat = UtcOffset.Format {
optional("GMT") {
offsetHours(Padding.NONE); char(':'); offsetMinutesOfHour()
optional { char(':'); offsetSecondsOfMinute() }
}
}
val offset = customFormat.parse("+01:30:15")
// Formatting a UtcOffset using both a custom format and a predefined one
check(offset.format(customFormat) == "+1:30:15")
check(offset.format(UtcOffset.Formats.FOUR_DIGITS) == "+0130")
//sampleEnd
}
actual fun Format(block: DateTimeFormatBuilder.WithUtcOffset.() -> Unit): DateTimeFormat<UtcOffset>(source)
actual fun Format(block: DateTimeFormatBuilder.WithUtcOffset.() -> Unit): DateTimeFormat<UtcOffset>(source)