Java Convert SQL Date to Calendar

Tags: Java SQL Date Java Calendar

In this Java core tutorial we learn how to convert a java.sql.Date object to a java.util.Calendar object in Java programming language.

How to convert SQL Date to Calendar in Java

In Java, with a given SQL Date object we can convert it to a Calendar object by using Calendar.setTime(Date date) to set the value of SQL date to the Calendar instance as the following example Java program.

ConvertSQLDateToCalendarExample1.java

import java.sql.Date;
import java.util.Calendar;

public class ConvertSQLDateToCalendarExample1 {
    public static void main(String... args) {
        Date date = Date.valueOf("2022-05-29");

        // Convert SQL Date object to Calendar object
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        System.out.println("SQL Date: " + date);
        System.out.println("Calendar Time: " + calendar.getTime());
    }
}
The output as below.
SQL Date: 2022-05-29
Calendar Time: Sun May 29 00:00:00 ICT 2022

Happy Coding 😊

Java Convert SQL Date to ZonedDateTime

Java Convert SQL Date to OffsetDateTime

Java Convert SQL Date to GregorianCalendar

Java Convert SQL Date to Instant

Java Convert LocalDate to SQL Date

Java Convert Instant to SQL Date

Java Convert LocalDateTime to SQL Date

Java Convert ZonedDateTime to SQL Date

Java Convert OffsetDateTime to SQL Date

Java Convert Date to SQL Date

Java Convert Calendar to SQL Date

Java Convert GregorianCalendar to SQL Date

Java Convert SQL Date to LocalDate

Java Convert SQL Date to LocalDateTime