Java.util.Calendar.getInstance() Method


Description

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

Declaration

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

public static Calendar getInstance()

Parameters

NA

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();

      // gets a calendar using the default time zone and locale.
      System.out.print("Date And Time Is: " + cal.getTime());
   }
}

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

Date And Time Is: Tue May 01 18:53:09 EEST 2012
java_util_calendar.htm
Advertisements