📜  Java.util.Calendar类

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


介绍

java.util.calendar类是一个抽象类,它提供用于在特定时间点和一组日历字段(例如YEAR,MONTH,DAY_OF_MONTH,HOUR等)之间进行转换以及操作日历字段的方法,例如作为获取下周的日期。以下是有关日历的要点-

  • 此类还提供了其他字段和方法,用于在程序包外部实现具体的日历系统。

  • 日历定义了某些日历字段返回的值的范围。

类声明

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

public abstract class Calendar
   extends Object
   implements Serializable, Cloneable, Comparable

领域

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

  • static int ALL_STYLES-这是getDisplayNames的样式说明符,用于指示所有样式的名称,例如“ January”和“ Jan”。

  • static int AM-这是AM_PM字段的值,指示从午夜到正午之前的一天的时间段。

  • static int AM_PM-这是get和set的字段号,指示HOUR是在中午之前还是之后。

  • static int APRIL-这是MONTH字段的值,指示公历和儒略历中的一年的第四个月。

  • protected boolean areFieldsSet-如果fields []与当前设置的时间同步,则为true。

  • static int AUGUST-这是MONTH字段的值,指示公历和儒略历中的一年的第八个月。

  • static int DATE-这是get和set的字段号,指示每月的日期。

  • static int DAY_OF_MONTH-这是get和set的字段号,指示月份的日期。

  • static int DAY_OF_WEEK-这是get和set的字段号,指示星期几。

  • 静态整数DAY_OF_WEEK_IN_MONTH-这是get和set的字段号,指示当前月份中星期几的序号。

  • static int DAY_OF_YEAR-这是get和set的字段编号,指示当前年份内的日期编号。

  • static int DECEMBER-这是MONTH字段的值,指示公历和儒略历中的一年的第十二个月。

  • static int DST_OFFSET-这是get和set的字段号,指示夏时制偏移量(以毫秒为单位)。

  • static int ERA-这是get和set的字段编号,指示时代,例如朱利安历法中的AD或BC。

  • static int 2月-这是MONTH字段的值,指示公历和儒略历中的一年的第二个月。

  • static int FIELD_COUNT-这是get和set识别的不同字段的数量。

  • protected int []字段-这是此日历当前设置时间的日历字段值。

  • static int FRIDAY-这是指示星期五的DAY_OF_WEEK字段的值。

  • static int HOUR-这是get和set的字段编号,指示早晨或下午的时间。

  • static int HOUR_OF_DAY-这是get和set的字段号,指示一天中的小时。

  • protected boolean [] isSet-这是标志,用于指示是否设置了日历的指定日历字段。

  • protected boolean isTimeSet-如果time的值有效,则为true。

  • static int JANUARY-这是MONTH字段的值,指示公历和儒略历中的一年的第一个月。

  • static int JULY-这是MONTH字段的值,指示公历和儒略历中的一年的第七个月。

  • static int JUNE-这是MONTH字段的值,指示公历和儒略历中的一年的第六个月。

  • static int LONG-这是getDisplayName和getDisplayNames的样式说明符,用于指示长名称,例如“ January”。

  • static int MARCH-这是MONTH字段的值,指示公历和儒略历中的每年的第三个月。

  • static int MAY-这是MONTH字段的值,指示公历和儒略历中的每年的第五个月。

  • static int MILLISECOND-这是get和set的字段编号,表示秒内的毫秒数。

  • static int MINUTE-这是get和set的字段号,指示小时内的分钟。

  • static int MONDAY-这是指示星期一的DAY_OF_WEEK字段的值。

  • static int MONTH-这是get和set的字段编号,表示月份。

  • static int NOVEMBER-这是MONTH字段的值,指示公历和儒略历中的每年的第十一个月。

  • static int OCTOBER-这是MONTH字段的值,指示公历和儒略历中的每年的第十个月。

  • static int PM-这是AM_PM字段的值,指示从中午到午夜之前的一天。

  • static int SATURDAY-这是DAY_OF_WEEK字段的值,指示星期六。

  • static int SECOND-这是get和set的字段号,指示分钟内的秒数。

  • static int SEPTEMBER-这是MONTH字段的值,指示公历和儒略历中的每年的第九个月。

  • static int SHORT-这是getDisplayName和getDisplayNames的样式说明符,用于指示短名称,例如“ Jan”。

  • static int SUNDAY-这是DAY_OF_WEEK字段的值,指示星期日。

  • static int THURSDAY-这是DAY_OF_WEEK字段的值,指示星期四。

  • 保护长时间-这是此日历的当前设置时间,以格林尼治标准时间1970年1月1日0:00:00之后的毫秒数表示。

  • static int TUESDAY-这是指示星期二的DAY_OF_WEEK字段的值。

  • static int UNDECIMBER-这是MONTH字段的值,指示一年中的第十三个月。

  • static int WEDNESDAY-这是指示星期三的DAY_OF_WEEK字段的值。

  • static int WEEK_OF_MONTH-这是get和set的字段号,指示当前月份内的星期号。

  • static int WEEK_OF_YEAR-这是get和set的字段号,指示当前年份内的星期号。 。

  • static int YEAR-这是get和set的字段编号,指示年份。

  • static int ZONE_OFFSET-这是get和set的字段编号,指示与GMT的原始偏移量(以毫秒为单位)。

类的构造函数

Sr.No. Constructor & Description
1

protected Calendar()

This constructor constructs a Calendar with the default time zone and locale.

2

protected Calendar(TimeZone zone, Locale aLocale)

This constructor constructs a calendar with the specified time zone and locale.

类方法

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

This method adds or subtracts the specified amount of time to the given calendar field, based on the calendar’s rules.

2 boolean after(Object when)

This method returns whether this Calendar represents a time after the time represented by the specified Object.

3 boolean before(Object when)

This method returns whether this Calendar represents a time before the time represented by the specified Object.

4 void clear()

This method sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

5 void clear(int field)

This method sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

6 Object clone()

This method creates and returns a copy of this object.

7 int compareTo(Calendar anotherCalendar)

This method compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.

8 protected void complete()

This method fills in any unset fields in the calendar fields.

9 protected abstract void computeFields()

This method converts the current millisecond time value time to calendar field values in fields[].

10 protected abstract void computeTime()

This method converts the current calendar field values in fields[] to the millisecond time value time.

11 boolean equals(Object obj)

This method compares this Calendar to the specified Object.

12 int get(int field)

This method returns the value of the given calendar field.

13 int getActualMaximum(int field)

This method returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

14 int getActualMinimum(int field)

This method returns the minimum value that the specified calendar field could have, given the time value of this Calendar.

15 static Locale[] getAvailableLocales()

This method returns an array of all locales for which the getInstance methods of this class can return localized instances.

16 String getDisplayName(int field, int style, Locale locale)

This method returns the string representation of the calendar field value in the given style and locale.

17 Map getDisplayNames(int field, int style, Locale locale)

This method returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values.

18 intgetFirstDayOfWeek()

This method gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

19 abstract int getGreatestMinimum(int field)

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

20 static Calendar getInstance()

This method gets a calendar using the default time zone and locale.

21 static Calendar getInstance(Locale aLocale)

This method gets a calendar using the default time zone and specified locale.

22 static Calendar getInstance(TimeZone zone)

This method gets a calendar using the specified time zone and default locale.

23 static Calendar getInstance(TimeZone zone, Locale aLocale)

This method gets a calendar with the specified time zone and locale.

24 abstract int getLeastMaximum(int field)

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

25 abstract int getMaximum(int field)

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

26 int getMinimalDaysInFirstWeek()

This method gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1.

27 abstract int getMinimum(int field)

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

28 Date getTime()

This method returns a Date object representing this Calendar’s time value (millisecond offset from the Epoch”).

29 long getTimeInMillis()

This method returns this Calendar’s time value in milliseconds.

30 TimeZone getTimeZone()

This method gets the time zone.

31 int hashCode()

This method Returns a hash code for this calendar.

32 protected int internalGet(int field)

This method returns the value of the given calendar field.

33 boolean isLenient()

This method tells whether date/time interpretation is to be lenient.

34 boolean isSet(int field)

This method determines if the given calendar field has a value set, including cases that the value has been set by internal fields calculations triggered by a get method call.

35 abstract 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.

36 void roll(int field, int amount)

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

37 void set(int field, int value)

This method sets the given calendar field to the given value.

38 void set(int year, int month, int date)

This method sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.

39 void set(int year, int month, int date, int hourOfDay, int minute)

This method sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE.

40 void set(int year, int month, int date, int hourOfDay, int minute, int second)

This method sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND.

41 void setFirstDayOfWeek(int value)

This method sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

42 void setLenient(boolean lenient)

This method specifies whether or not date/time interpretation is to be lenient.

43 void setMinimalDaysInFirstWeek(int value)

This method sets what the minimal days required in the first week of the year are; For Example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value.

44 void setTime(Date date)

This method sets this Calendar’s time with the given Date.

45 void setTimeInMillis(long millis)

This method sets this Calendar’s current time from the given long value.

46 void setTimeZone(TimeZone value)

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

47 String toString()

This method return a string representation of this calendar.

方法继承

此类从以下类继承方法-

  • java.util.Object