Gregorian Calendar in Java

Java 8Object Oriented ProgrammingProgramming

GregorianCalendar is a hybrid calendar that supports both the Julian and Gregorian calendar systems with the support of a single discontinuity, which corresponds by default to the Gregorian date when the Gregorian calendar was instituted.

The java.util.GregorianCalendar class in Java is a concrete subclass of Calendar and provides the standard calendar system used by most of the world.

Import the following package to work with GregorianCalendar class.

import java.util.GregorianCalendar;

The following are the constructors.

Sr.No.Constructor & Description
1GregorianCalendar() 

This constructs a default GregorianCalendar using the current time in the default time zone with the default locale.
2GregorianCalendar(int year, int month, int dayOfMonth) 

This constructs a GregorianCalendar with the given date set in the default time zone with the default locale.
3GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute)  
 
This constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
4GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second)

 This constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
5GregorianCalendar(Locale aLocale) 

This constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
6GregorianCalendar(TimeZone zone) 

This constructs a GregorianCalendar based on the current time in the given time zone with the default locale.
7GregorianCalendar(TimeZone zone, Locale aLocale) 

This constructs a GregorianCalendar based on the current time in the given time zone with the given locale.

Example

 Live Demo

import java.util.GregorianCalendar;
public class Demo {
   public static void main(String[] args) {
      GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
      System.out.println("" + cal.getTime());
   }
}

Output

Mon Nov 19 15:57:40 UTC 2018
raja
Published on 17-Dec-2018 12:02:20
Advertisements