.offsetAt()
Published Nov 14, 2023
Contribute to Docs
The .offsetAt()
method is used to find the offset from UTC(Coordinated Universal time) for a specific time zone at a specified instant
in physical time.
Syntax
fun TimeZone.offsetAt(instant: Instant): UtcOffset
Instant
: A moment in time.UtcOffset
: An offset from UTC (Coordinated Universal Time).TimeZone
: Provides a conversion betweenInstant
andLocalDateTime
values using a collection of rules.
Example
The example given below provides the offset for Asia/Kolkata
time zone at a specified instant.
import kotlinx.datetime.Instantimport kotlinx.datetime.TimeZonefun main() {val instant = Instant.parse("2023-11-07T12:00:00Z")val timeZone = TimeZone.of("Asia/Kolkata")val offset = timeZone.offsetAt(instant)println("At $instant, the offset from UTC in ${timeZone.id} is $offset.")}
Note: The string
2023-11-07T12:00:00Z
specifies date and time of November 7, 2023, at 12:00:00 UTC. TheT
separates the date and time components, andZ
indicates that the time is in UTC.
The above example will result in the following output:
At 2023-11-07T12:00:00Z, the offset from UTC in Asia/Kolkata is +05:30.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.