ISO
ISO 8601 extended format, which is the format used by UtcOffset.parse and UtcOffset.toString.
An extension of ISO 8601 that allows parsing and formatting seconds.
When formatting, seconds are omitted if they are zero. If the whole offset is zero, the letter Z
is output.
Examples of UTC offsets in ISO 8601 format:
Z
or+00:00
, an offset of zero;+05:00
, five hours;-02:00
, minus two hours;-17:16
+10:36:30
See ISO-8601-1:2019, 4.3.13c), extended to support seconds-of-minute when they are non-zero.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Using the extended ISO format for parsing and formatting UtcOffset values
val offset = UtcOffset.Formats.ISO.parse("+10:36:22")
check(offset == UtcOffset(hours = 10, minutes = 36, seconds = 22))
val formatted = UtcOffset.Formats.ISO.format(offset)
check(formatted == "+10:36:22")
//sampleEnd
}