Java TimeZone create from ZoneId

Description

Java TimeZone create from ZoneId

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;

public class Main {
  public static void main(String[] args) {
     ZonedDateTime zdt = ZonedDateTime.now();
     System.out.println("Zoned DateTime:  " + zdt);
     //from  w  ww  . java 2 s  .c  om
     ZoneId zoneId = zdt.getZone();
     TimeZone timeZone = TimeZone.getTimeZone(zoneId);

     System.out.println("Zone ID:  " + zoneId);
     System.out.println("Time Zone ID:  " + timeZone.getID());

  }
}



PreviousNext

Related