Given a timezone (America/New_York
), how do I go about getting the UTC offset?
I have tried using java.util.TimeZone
but had no luck. I am fine with using Joda Time as well if the solution is viable in that.
Given a timezone (America/New_York
), how do I go about getting the UTC offset?
I have tried using java.util.TimeZone
but had no luck. I am fine with using Joda Time as well if the solution is viable in that.
The offset for a particular time zone can vary based on the current time because of daylight savings, etc. UTC doesn't have daylight savings, but "America/New_York" will change offsets with the daylight savings switch. Therefore, the offset is a function of both the current time and the timezone. The answers here give some examples of how to get the current offset:
Note: Current offset depends on
This is well described in near answer.
Useful snippets:
TimeZone.getTimeZone("Europe/Kiev").getOffset(Instant.now().toEpochMilli());
will give you integer offset in milliseconsString.format("%tz", Instant.now().atZone(ZoneId.of("Europe/Kiev")));
will give you a standardized string representation like "+0300"