Format Calendar with String Format in Java



Firstly, consider an object with date value.

Object arrObj[] = { "Date", Calendar.getInstance() };

After that, use the String.format() method to format Calendar and display the date.

The following is an example.

Example

 Live Demo

import java.util.Calendar;
public class Demo {
   public static void main(String []args){
      Object arrObj[] = { "Date", Calendar.getInstance() };
      System.out.println("Formatting Date...");
      System.out.println(String.format("%1$s = %2$tY %2$tm %2$te", arrObj));
   }
}

Output

Formatting Date...
Date = 2018 11 17
Updated on: 2020-06-27T06:16:23+05:30

898 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements