TimeZone

@Serializable(with = TimeZoneSerializer::class)
actual open class TimeZone(source)

Inheritors

@Serializable(with = TimeZoneSerializer::class)
expect open class TimeZone(source)

A time zone, provides the conversion between Instant and LocalDateTime values using a collection of rules specifying which LocalDateTime value corresponds to each Instant.

A time zone can be used in Instant.toLocalDateTime and LocalDateTime.toInstant, and also in those arithmetic operations on Instant that require knowing the calendar.

A TimeZone can be constructed using the TimeZone.of function, which accepts the string identifier, like "Europe/Berlin", "America/Los_Angeles", etc. For a list of such identifiers, see TimeZone.availableZoneIds. Also, the constant TimeZone.UTC is provided for the UTC time zone.

For interaction with kotlinx-serialization, TimeZoneSerializer is provided that serializes the time zone as its identifier.

On the JVM, there are TimeZone.toJavaZoneId() and java.time.ZoneId.toKotlinTimeZone() extension functions to convert between kotlinx.datetime and java.time objects used for the same purpose. Similarly, on the Darwin platforms, there are TimeZone.toNSTimeZone() and NSTimeZone.toKotlinTimeZone() extension functions.

Samples

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

fun main() { 
   //sampleStart 
   // Using a time zone to convert a local date-time to an instant and back
val zone = TimeZone.of("Europe/Berlin")
val localDateTime = LocalDate(2021, 3, 28).atTime(2, 16, 20)
val instant = localDateTime.toInstant(zone)
check(instant == Instant.parse("2021-03-28T01:16:20Z"))
val newLocalDateTime = instant.toLocalDateTime(zone)
check(newLocalDateTime == LocalDate(2021, 3, 28).atTime(3, 16, 20)) 
   //sampleEnd
}

Inheritors

@Serializable(with = TimeZoneSerializer::class)
actual open class TimeZone(source)

Inheritors

@Serializable(with = TimeZoneSerializer::class)
actual open class TimeZone(source)

Inheritors

Types

Link copied to clipboard
actual object Companion
expect object Companion
actual object Companion
actual object Companion

Properties

Link copied to clipboard
actual val id: String
expect val id: String

Returns the identifier string of the time zone.

actual val id: String
actual open val id: String

Functions

Link copied to clipboard
actual open operator override fun equals(other: Any?): Boolean
expect open operator override fun equals(other: Any?): Boolean

Compares this time zone to the other one. Time zones are equal if their identifier is the same.

actual open operator override fun equals(other: Any?): Boolean
actual open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
open override fun hashCode(): Int
open override fun hashCode(): Int
open override fun hashCode(): Int
Link copied to clipboard
actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
expect fun TimeZone.offsetAt(instant: Instant): UtcOffset

Finds the offset from UTC this time zone has at the specified instant of physical time.

actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
actual fun TimeZone.offsetAt(instant: Instant): UtcOffset
Link copied to clipboard

Returns an instant that corresponds to this civil datetime value in the time zone provided as an implicit receiver.

Link copied to clipboard
Link copied to clipboard

Return the civil datetime value that this instant has in the time zone provided as an implicit receiver.

Link copied to clipboard
fun TimeZone.toNSTimeZone(): <Error class: unknown class>

Converts the TimeZone to NSTimeZone.

Link copied to clipboard
actual open override fun toString(): String
expect open override fun toString(): String

Equivalent to id.

actual open override fun toString(): String
actual open override fun toString(): String