Java Data Type How to - Convert ZoneId to TimeZone








Question

We would like to know how to convert ZoneId to TimeZone.

Answer

//from   w  w  w .j av a2  s  .c  o m
import java.time.ZoneId;
import java.util.TimeZone;

public class Main {
    public static void main(String[] args) {
      ZoneId defaultZone = TimeZone.getDefault().toZoneId();
      
      TimeZone tz = TimeZone.getTimeZone(defaultZone);
      System.out.println(tz);
    }
}

The code above generates the following result.