Why does joda DateTimeZone's getOffset() method require an "instant"?
datetime, java, jodatime, timezone
Solution
This is, because the Offset changes over time. One example is daylight saving time. Another is a country deciding to move to another timezone.
If you want the current offset, just hand in now like this:
int offset = DateTimeZone.forID("Europe/Berlin").getOffset(new DateTime());
System.out.println(offset);
Problem
What I'm trying to do: From a DateTimeZone object, I'm trying to get the GMT offset in milliseconds. Example: ``` DateTimeZone gmt= // somehow get gmt zone object long offset = gmt.getOffsetSomehow(); // expect offset = 0 DateTimeZone ny_est = // somehow get that time zone object representing "EST" offset of NY zone long offset = ny_est.getOffsetSomehow(); // expect offset = -18000000 = -5*60*60*1000 DateTimeZone hkt = // somehow get HK time zone object long offset = hkt.getOffsetSomehow(); // expect offset = 28800000 = 8*60*60*1000 ``` Joda's DateTimeZone object has a method called getOffset, which accepts a parameter. Question: - why does that method need a parameter? I would have expected the method to not expect any param, and simply behave how I want my fictitious "getOffsetSomehow()" method. - How can I get the time zone objects in my snippet above? - What actual method/snippet of code can get me the "offset" values I'm try to get?