Using Java I have a SimpleTimeZone
instance with GMT offset and daylight saving time information from a legacy system.
I would like to retrieve Zo
Here the solution i prefer because it's simple, but you need a Date and a TimeZone as parameters to retrievethe the ZoneId
private ZoneId getZoneOffsetFor(final Date date, final TimeZone timeZone){
int offsetInMillis = getOffsetInMillis(date, timeZone);
return ZoneOffset.ofTotalSeconds( offsetInMillis / 1000 );
}
private int getOffsetInMillis(final Date date, final TimeZone timeZone){
int offsetInMillis = timeZone.getRawOffset();
if(timeZone.inDaylightTime(date)){
offsetInMillis += timeZone.getDSTSavings();
}
return offsetInMillis;
}