timeZoneId

The timezone identifier, for example, "Europe/Berlin".

Samples

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

fun main() { 
   //sampleStart 
   // Formatting and parsing a time zone ID as part of a complex format
val formatWithTimeZone = DateTimeComponents.Format {
    dateTime(LocalDateTime.Formats.ISO)
    char('[')
    timeZoneId()
    char(']')
}
val formattedWithTimeZone = formatWithTimeZone.format {
    setDateTime(LocalDate(2021, 3, 28).atTime(2, 16, 20))
    timeZoneId = "America/New_York"
}
check(formattedWithTimeZone == "2021-03-28T02:16:20[America/New_York]")
val parsedWithTimeZone = DateTimeComponents.parse(formattedWithTimeZone, formatWithTimeZone)
check(parsedWithTimeZone.timeZoneId == "America/New_York")
try {
    formatWithTimeZone.parse("2021-03-28T02:16:20[Mars/Phobos]")
    fail("Expected an exception")
} catch (e: DateTimeFormatException) {
    // expected: the time zone ID is invalid
} 
   //sampleEnd
}