of
Returns the time zone identified by the provided zoneId.
The supported variants of time zone identifiers:
Z, 'UTC', 'UT' or 'GMT' — identifies the fixed-offset time zone TimeZone.UTC,a string starting with '+', '-',
UTC+,UTC-,UT+,UT-,GMT+,GMT-— identifiers the time zone with the fixed offset specified after+or-,all other strings are treated as region-based zone identifiers. In the IANA Time Zone Database (TZDB) which is used as the default source of time zones, these ids are usually in the form
area/city, for example,Europe/BerlinorAmerica/Los_Angeles.
It is guaranteed that passing any value from availableZoneIds to this function will return a valid time zone.
Throws
on the Wasm WASI platform for non-fixed-offset time zones, unless a dependency on the kotlinx-datetime-zoneinfo artifact is added.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Constructing a time zone using the factory function
val zone = TimeZone.of("America/New_York")
check(zone.id == "America/New_York")
//sampleEnd
}