offsetIn

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

Pitfall: the offset returned from this function should typically not be used for datetime arithmetics because the offset can change over time due to daylight-saving-time transitions and other reasons. Use TimeZone directly with arithmetic operations instead.

See also

Samples

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

fun main() { 
   //sampleStart 
   // Obtaining the offset of a time zone at a specific instant
val zone = TimeZone.of("America/New_York")
val instant = Instant.parse("2023-06-02T12:30:00Z")
val offset = instant.offsetIn(zone)
check(offset == UtcOffset(hours = -4)) 
   //sampleEnd
}