Java Utility Library

Java Calendar - getInstance() Method



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

Syntax

public static Calendar getInstance(TimeZone zone,
                                   Locale aLocale)

Parameters

aLocale Specify the locale for the week data.
zone Specify the time zone to use.

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 timezone  
    TimeZone tz = TimeZone.getTimeZone("CST");  

    //create a new locale  
    Locale locale = new Locale("EN", "US"); 

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

    //printing calendar timezone and locale
    String tzname = Cal.getTimeZone().getDisplayName();
    String locname = locale.getDisplayName();
    System.out.println("The Calendar is using:");
    System.out.println("TimeZone: " + tzname);
    System.out.println("Locale: " + locname);
  }
}

The output of the above code will be:

The Calendar is using:
TimeZone: Central Standard Time
Locale: English (United States)

❮ Java.util - Calendar