Hi all. I'm trying to convert an instant from loca...
# kotlinx-datetime
a
Hi all. I'm trying to convert an instant from local time zone (e.g. America/New_York) to UTC (with offset) which should be (at this moment in time) +5 hours. When I'm trying to calculate offset in time zone UTC I get no change (printing it shows "Z"). How can I convert from local time zone adjusted to UTC where the delta is taken into account properly? It seems right now, whatever the instant is it will just be used as is but with UTC with no datetime change.
s
Can you share an example?
a
As in code or simply use case?
s
What's an example input, and what output do you want for that input?
d
You can't convert an instant from a local time zone to anything, because instants are independent of time zones.
LocalDateTime
is defined in terms of time zones. For example,
LocalDateTime(2024, 12, 11, 8, 29).toInstant(TimeZone.of("America/New_York")).toLocalDateTime(TimeZone.UTC)
finds the instant corresponding to when clocks in New York show 2024-12-11 08:29 AM and then finds what clocks in the UTC time zone show at that instant.
thank you color 1