Java Convert Date to Calendar

Tags: Java Date Java Calendar

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

How to convert Date to Calendar in Java

With Java we can use the Calendar.setTime() method to set a Date value to a Calendar object. The following Java example to show how to use this method to convert a Date object to a Calendar object.

ConvertDateToCalendarExample1.java

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

public class ConvertDateToCalendarExample1 {
    public static void main(String... args) {
        Date date = new Date();

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

        System.out.println("Date: " + date);
        System.out.println("Calendar Day of Month: " + calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println("Calendar Month: " + calendar.get(Calendar.MONTH));
        System.out.println("Calendar Year: " + calendar.get(Calendar.YEAR));
    }
}
The output as below.
Date: Sat Apr 16 16:57:33 ICT 2022
Calendar Day of Month: 16
Calendar Month: 3
Calendar Year: 2022

Happy Coding 😊

Java Convert Calendar to Date

Java Convert Date to Milliseconds

Java Convert Date to String

Java Convert Date to Instant

Java Date by Examples

Java Calendar by Examples