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 specified locale. The Calendar returned is based on the current time in the default time zone with the given locale.

Syntax

public static Calendar getInstance(Locale aLocale)

Parameters

aLocale Specify the locale for the week data.

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) {
    //create a new locale  
    Locale locale = new Locale("EN", "US");  

    //creating a Calendar instance
    Calendar Cal = Calendar.getInstance(locale);

    //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:40:31 UTC 2021

❮ Java.util - Calendar