Java GregorianCalendar convert to LocalTime

Introduction

To convert GregorianCalendar to LocalTime, convert ZonedDateTime and then call toLocalTime() method.

import java.time.LocalTime;
import java.util.GregorianCalendar;

public class Main {
  public static void main(String[] args) {
     GregorianCalendar gc = new GregorianCalendar(2020, 2, 21, 15, 23, 39);
     /*  ww  w .j a v a2  s .  c o  m*/
     LocalTime lt = gc.toZonedDateTime().toLocalTime();
     System.out.println("Local Time:  " + lt);
  }
}



PreviousNext

Related