📜  Java.util.GregorianCalendar类

📅  最后修改于: 2020-11-14 06:16:39             🧑  作者: Mango


介绍

java.util.GregorianCalendar类是Calendar的一个具体子类,提供了世界上大多数地方使用的标准日历系统。以下是GregorianCalendar的重点-

  • 它是一种混合日历,在单个不连续性的支持下支持儒略历和公历系统,默认情况下,该日历对应于建立公历的公历日期。

  • 朱利安历法指定每四年leap年,而公历忽略了不可被400整除的世纪年。

类声明

以下是java.util.GregorianCalendar类的声明-

public class GregorianCalendar
   extends Calendar

领域

以下是java.util.GregorianCalendar类的字段-

  • static int AD-这是ERA字段的值,指示通用时代(Anno Domini),也称为CE。

  • static int BC-这是ERA字段的值,指示普通时代之前(基督之前),也称为BCE。

类的构造函数

Sr.No. Constructor & Description
1

GregorianCalendar()

This constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

2

GregorianCalendar(int year, int month, int dayOfMonth)

This 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)

This 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)

This constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

5

GregorianCalendar(Locale aLocale)

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

6

GregorianCalendar(TimeZone zone)

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

7

GregorianCalendar(TimeZone zone, Locale aLocale)

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

类方法

Sr.No. Method & Description
1 void add(int field, int amount)

This method adds the specified (signed) amount of time to the given calendar field, based on the calendar’s rules.

2 Object clone()

This method creates and returns a copy of this object.

3 protected void computeFields()

This method converts the time value (millisecond offset from the Epoch) to calendar field values.

4 protected void computeTime()

This method converts calendar field values to the time value (millisecond offset from the Epoch).

5 boolean equals(Object obj)

This method compares this GregorianCalendar to the specified Object.

6 int getActualMaximum(int field)

This method 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.

7 int getActualMinimum(int field)

This method 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.

8 int getGreatestMinimum(int field)

This method returns the highest minimum value for the given calendar field of this GregorianCalendar instance.

9 Date getGregorianChange()

This method gets the Gregorian Calendar change date.

10 int getLeastMaximum(int field)

This method returns the lowest maximum value for the given calendar field of this GregorianCalendar instance.

11 int getMaximum(int field)

This method returns the maximum value for the given calendar field of this GregorianCalendar instance.

12 int getMinimum(int field)

This method returns the minimum value for the given calendar field of this GregorianCalendar instance.

13 TimeZone getTimeZone()

This method gets the time zone.

14 int hashCode()

This method generates the hash code for this GregorianCalendar object.

15 boolean isLeapYear(int year)

This method determines if the given year is a leap year.

16 void roll(int field, boolean up)

This method adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.

17 void roll(int field, int amount)

This method adds a signed amount to the specified calendar field without changing larger fields.

18 void setGregorianChange(Date date)

This method sets the GregorianCalendar change date.

19 setTimeZone(TimeZone zone)

This method sets the time zone with the given time zone value.

方法继承

此类从以下类继承方法-

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