Java.util.Calendar.getInstance() Method
Description
The java.util.Calendar.getInstance() method Gets a calendar using the specified time zone and current locale.
Declaration
Following is the declaration for java.util.Calendar.getInstance() method
public static Calendar getInstance(TimeZone zone)
Parameters
zone − the time zone 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
TimeZone tz1 = TimeZone.getTimeZone("GMT");
Calendar cal1 = Calendar.getInstance(tz1);
// create a second calendar with different timezone
TimeZone tz2 = TimeZone.getTimeZone("EST");
Calendar cal2 = Calendar.getInstance(tz2);
// display time zone for both calendars
System.out.println("GMT: " + cal1.getTimeZone().getDisplayName());
System.out.println("EST: " + cal2.getTimeZone().getDisplayName());
}
}
Let us compile and run the above program, this will produce the following result −
GMT: Greenwich Mean Time EST: Eastern Standard Time
java_util_calendar.htm
Advertisements