Java Data Type How to - Convert GregorianCalendar to ZonedDateTime








Question

We would like to know how to convert GregorianCalendar to ZonedDateTime.

Answer

import java.time.ZonedDateTime;
import java.util.GregorianCalendar;
//ww  w.  ja  va2 s.c o  m
public class Main {

  public static void main(String[] args) {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    ZonedDateTime d = gregorianCalendar.toZonedDateTime();
    System.out.println(d);

  }
}

The code above generates the following result.