time Zone Id
The timezone identifier, for example, "Europe/Berlin".
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
import kotlin.time.Instant
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")
//sampleEnd
}