Facebook Page Twitter Page LinkedIn Page
× Java Utility Library


Java GregorianCalendar Class

Java.util package provides a GregorianCalendar class which is a concrete subclass of Calendar and provides the standard calendar system used by most of the world. 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 only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400.

Class declaration

The declaration of java.util.GregorianCalendar class is:

public class GregorianCalendar
  extends Calendar

Fields

S.NFields and Description
1. static int AD
Value of the ERA field indicating the common era (Anno Domini), also known as CE.
2. static int BC
Value of the ERA field indicating the period before the common era (before Christ), also known as BCE.

Class Constructors

S.NConstructors & Description
1. GregorianCalendar()
Constructs a default GregorianCalendar using the current time in the default time zone with the default FORMAT locale.
2. GregorianCalendar(int year, int month, int dayOfMonth)
Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.
3. GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
4. GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
5. GregorianCalendar(Locale aLocale)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
6. GregorianCalendar(TimeZone zone)
Constructs a GregorianCalendar based on the current time in the given time zone with the default FORMAT locale.
7. GregorianCalendar(TimeZone zone, Locale aLocale)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.

java.util.GregorianCalendar Methods

The java.util.GregorianCalendar class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. void add(int field, int amount)
Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.
2. Object clone()
Creates and returns a copy of this object.
3. protected void computeFields()
Converts the time value (millisecond offset from the Epoch) to calendar field values.
4. protected void computeTime()
Converts calendar field values to the time value (millisecond offset from the Epoch).
5. boolean equals(Object obj)
Compares this GregorianCalendar to the specified Object.
6. static GregorianCalendar from(ZonedDateTime zdt)
Obtains an instance of GregorianCalendar with the default locale from a ZonedDateTime object.
7. int getActualMaximum(int field)
Returns the maximum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
8. int getActualMinimum(int field)
Returns the minimum value that this calendar field could have, taking into consideration the given time value and the current values of the getFirstDayOfWeek, getMinimalDaysInFirstWeek, getGregorianChange and getTimeZone methods.
9. String getCalendarType()
Returns "gregory" as the calendar type.
10. int getGreatestMinimum(int field)
Returns the highest minimum value for the given calendar field of this GregorianCalendar instance.
11. Date getGregorianChange()
Gets the Gregorian Calendar change date.
12. int getLeastMaximum(int field)
Returns the lowest maximum value for the given calendar field of this GregorianCalendar instance.
13. int getMaximum(int field)
Returns the maximum value for the given calendar field of this GregorianCalendar instance.
14. int getMinimum(int field)
Returns the minimum value for the given calendar field of this GregorianCalendar instance.
15. TimeZone getTimeZone()
Gets the time zone.
16. int getWeeksInWeekYear()
Returns the number of weeks in the week year represented by this GregorianCalendar.
17. int getWeekYear()
Returns the week year represented by this GregorianCalendar.
18. int hashCode()
Generates the hash code for this GregorianCalendar object.
19. boolean isLeapYear(int year)
Determines if the given year is a leap year.
20. boolean isWeekDateSupported()
Returns true indicating this GregorianCalendar supports week dates.
21. void roll(int field, boolean up)
Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.
22. void roll(int field, int amount)
Adds a signed amount to the specified calendar field without changing larger fields.
23. void setGregorianChange(Date date)
Sets the GregorianCalendar change date.
24. void setTimeZone(TimeZone zone)
Sets the time zone with the given time zone value.
25. void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek)
Sets this GregorianCalendar to the date given by the date specifiers - weekYear, weekOfYear, and dayOfWeek.
26. ZonedDateTime toZonedDateTime()
Converts this object to a ZonedDateTime that represents the same point on the time-line as this GregorianCalendar.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object
  • java.util.Calendar

5