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:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With