3

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.

RainSear
  • 629
  • 1
  • 8
  • 13
  • TimeZone should work, please add the code you've tried to the question, and include any exceptions, output, etc. – blm Oct 08 '15 at 22:52

2 Answers2

9

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:

Java TimeZone offset

Community
  • 1
  • 1
Monz
  • 321
  • 2
  • 11
3

Note: Current offset depends on

  • raw tz-offset
  • day-savings time (DST) for a CURRENT moment.

This is well described in near answer.

Useful snippets:

  • TimeZone.getTimeZone("Europe/Kiev").getOffset(Instant.now().toEpochMilli()); will give you integer offset in millisecons
  • String.format("%tz", Instant.now().atZone(ZoneId.of("Europe/Kiev"))); will give you a standardized string representation like "+0300"