Java GregorianCalendar convert to LocalDateTime

Introduction

To convert GregorianCalendar to LocalDateTime, convert ZonedDateTime and then call toLocalDateTime() method.

import java.time.LocalDateTime;
import java.util.GregorianCalendar;

public class Main {
  public static void main(String[] args) {
     GregorianCalendar gc = new GregorianCalendar(2020, 2, 21, 15, 23, 39);
     //w w w. j ava 2  s  . co m
     LocalDateTime ldt = gc.toZonedDateTime().toLocalDateTime();
     System.out.println("Local DateTime:  " + ldt);
  }
}



PreviousNext

Related