asTimeZone

Returns the fixed-offset time zone with the given UTC offset.

Pitfall: UTC offsets are static values and do not change with time. If the logic requires that the offset changes with time, for example, to account for daylight-saving-time transitions, use TimeZone.of with an IANA time zone name to obtain a time zone that can handle changes in the offset.

Samples

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

fun main() { 
   //sampleStart 
   // Converting a UtcOffset to a fixed-offset TimeZone
UtcOffset(hours = 3, minutes = 30).asTimeZone().let { timeZone ->
    check(timeZone.id == "+03:30")
    check(timeZone.offset == UtcOffset(hours = 3, minutes = 30))
} 
   //sampleEnd
}