Java Utility Library

Java Calendar - getInstance() Method



The java.util.Calendar.getInstance() method is used to get a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default FORMAT locale.

Syntax

public static Calendar getInstance()

Parameters

No parameter is required.

Return Value

Returns a Calendar.

Exception

NA

Example:

In the example below, the java.util.Calendar.getInstance() method is used to create a Calendar instance.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Calendar instance
    Calendar Cal = Calendar.getInstance();

    //Creating a date object from calendar and printing it
    System.out.println("The Calendar is: " + Cal.getTime());
  }
}

The output of the above code will be:

The Calendar is: Sat May 08 10:39:58 UTC 2021

❮ Java.util - Calendar