Java.util.Calendar.getInstance() Method



Description

The java.util.Calendar.getInstance() method gets a calendar using the current time zone and specified locale.

Declaration

Following is the declaration for java.util.Calendar.getInstance() method

public static Calendar getInstance(Locale locale)

Parameters

locale − the locale for the calendar data

Return Value

The method returns a Calendar.

Exception

NA

Example

The following example shows the usage of java.util.calendar.getInstance() method.

package com.tutorialspoint;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

      // create a calendar
      Calendar cal = Calendar.getInstance(Locale.CANADA);

      // print the date for canada 
      System.out.println("Date And Time in Canada Is: " + cal.getTime());
   }
}

Let us compile and run the above program, this will produce the following result −

Date And Time in China Is: Tue May 01 19:05:34 EEST 2012
java_util_calendar.htm
Advertisements