Java Convert Calendar to String

Tags: Java Calendar String

In this Java core tutorial we learn how to convert a java.util.Calendar object to a date time format String in Java programming language.

How to format Calendar to date time String

In Java we can use SimpleDateFormat class to format a Date object into date time String. The following Java program we use the SimpleDateFormat to format Date object which return from Calendar.getTime() method of a given Calendar object.

ConvertCalendarToStringExample1.java

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class ConvertCalendarToStringExample1 {
    public static void main(String... args) {
        Calendar calendar = Calendar.getInstance();

        // Convert Calendar to String
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String formattedDate = simpleDateFormat.format(calendar.getTime());

        System.out.println(formattedDate);
    }
}
The output as below.
2022/04/16 13:59:42

Happy Coding 😊

Java Convert Calendar to Date

Java Convert Calendar to Milliseconds

Java Convert Calendar to Instant

Java Calendar by Examples

Java Calendar using Calendar.Builder by Examples