time Zone Id
The IANA time zone identifier, for example, "Europe/Berlin".
When formatting, the timezone identifier is supplied as is, without any validation. On parsing, TimeZone.availableZoneIds is used to validate the identifier.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Defining a custom format that includes a time zone ID
val format = DateTimeComponents.Format {
dateTime(LocalDateTime.Formats.ISO)
char('[')
timeZoneId()
char(']')
}
val formatted = format.format {
setDateTime(LocalDate(2021, 1, 13).atTime(9, 34, 58, 120_000_000))
timeZoneId = "Europe/Paris"
}
check(formatted == "2021-01-13T09:34:58.12[Europe/Paris]")
val parsed = format.parse("2021-01-13T09:34:58.12[Europe/Paris]")
check(parsed.toLocalDateTime() == LocalDate(2021, 1, 13).atTime(9, 34, 58, 120_000_000))
check(parsed.timeZoneId == "Europe/Paris")
//sampleEnd
}