I m using ZonedDateTime library from Java to retrieve UTC offset of any timezone out of the standard timezone list (Olson timezone database).
Here is my simple code.
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class HelloWorld{
public static void main(String []args){
displayUtcOffset("Europe/Istanbul");
displayUtcOffset("America/Caracas");
}
public static void displayUtcOffset(String olsonId){
ZonedDateTime zonedDateTime = ZonedDateTime.now(ZoneId.of(olsonId));
float utcOffset = zonedDateTime.getOffset().getTotalSeconds()/3600f;
System.out.println("For "+olsonId+", UTC"+utcOffset);
}
}
And the output of these is,
For Europe/Istanbul, UTC2.0
For America/Caracas, UTC-4.5
As we see UTC offset for Caracas is correct but that for Istanbul is actually +3 but it gives output as +2 which is incorrect. Has there been some change to the way this java library works? or is there a more reliable library for converting olson Id to UTC offset?
Note: olson Ids List