Java TimeZone create from ZonedDateTime

Introduction

To create TimeZone from ZonedDateTime, use the getTimeZone() method.

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);
     /*w w w.j  av a  2s  .com*/
     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