Java GregorianCalendar convert to LocalDate

Introduction

To convert GregorianCalendar to LocalDate, convert ZonedDateTime and then call toLocalDate() method.

import java.time.LocalDate;
import java.util.GregorianCalendar;

public class Main {
  public static void main(String[] args) {
     GregorianCalendar gc = new GregorianCalendar(2020, 2, 21, 15, 23, 39);
     LocalDate ld = gc.toZonedDateTime().toLocalDate();
     System.out.println("Local  Date: " + ld);
  }//  www.  ja  v a  2s.c  o m
}



PreviousNext

Related