Top Description Inners Fields Constructors Methods
com.ibm.icu.util

public abstract Class Calendar

extends Object
implements Serializable, Cloneable, Comparable<Calendar>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable, java.lang.Cloneable, java.io.Serializable
Known Direct Subclasses
com.ibm.icu.util.CECalendar, com.ibm.icu.util.ChineseCalendar, com.ibm.icu.util.PersianCalendar, com.ibm.icu.util.GregorianCalendar, com.ibm.icu.util.HebrewCalendar, com.ibm.icu.util.IndianCalendar, com.ibm.icu.util.IslamicCalendar
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.text.StringCharacterIterator, java.util.ArrayList, .Date, .Locale, .MissingResourceException, com.ibm.icu.impl.CalType, .CalendarUtil, .ICUCache, .ICUData, .ICUResourceBundle, .SimpleCache, .SimpleFormatterImpl, .SoftCache, com.ibm.icu.text.DateFormat, .DateFormatSymbols, .DateTimePatternGenerator, .SimpleDateFormat, com.ibm.icu.util.BasicTimeZone.LocalOption, .ULocale.Category

ICU Enhancement

This class is ICU's replacement for java.util.Calendar.

ICU

Methods, fields, and other functionality specific to ICU are labeled 'ICU'.

Calendar is an abstract base class for converting between a Date object and a set of integer fields such as YEAR, MONTH, DAY, HOUR, and so on. (A Date object represents a specific instant in time with millisecond precision. See Date for information about the Date class.)

Subclasses of Calendar interpret a Date according to the rules of a specific calendar system. ICU4J contains several subclasses implementing different international calendar systems.

Like other locale-sensitive classes, Calendar provides a class method, getInstance, for getting a generally useful object of this type. Calendar's getInstance method returns a calendar of a type appropriate to the locale, whose time fields have been initialized with the current date and time:

Calendar rightNow = Calendar.getInstance()

When a ULocale is used by getInstance, its 'calendar' tag and value are retrieved if present. If a recognized value is supplied, a calendar is provided and configured as appropriate. Currently recognized tags are "buddhist", "chinese", "coptic", "ethiopic", "gregorian", "hebrew", "islamic", "islamic-civil", "japanese", and "roc". For example:

Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=japanese"));
will return an instance of JapaneseCalendar (using en_US conventions for minimum days in first week, start day of week, et cetera).

A Calendar object can produce all the time field values needed to implement the date-time formatting for a particular language and calendar style (for example, Japanese-Gregorian, Japanese-Traditional). Calendar defines the range of values returned by certain fields, as well as their meaning. For example, the first month of the year has value MONTH == JANUARY for all calendars. Other values are defined by the concrete subclass, such as ERA and YEAR. See individual field documentation and subclass documentation for details.

When a Calendar is lenient, it accepts a wider range of field values than it produces. For example, a lenient GregorianCalendar interprets MONTH == JANUARY, DAY_OF_MONTH == 32 as February 1. A non-lenient GregorianCalendar throws an exception when given out-of-range field settings. When calendars recompute field values for return by get(), they normalize them. For example, a GregorianCalendar always produces DAY_OF_MONTH values between 1 and the length of the month.

Calendar defines a locale-specific seven day week using two parameters: the first day of the week and the minimal days in first week (from 1 to 7). These numbers are taken from the locale resource data when a Calendar is constructed. They may also be specified explicitly through the API.

When setting or getting the WEEK_OF_MONTH or WEEK_OF_YEAR fields, Calendar must determine the first week of the month or year as a reference point. The first week of a month or year is defined as the earliest seven day period beginning on getFirstDayOfWeek() and containing at least getMinimalDaysInFirstWeek() days of that month or year. Weeks numbered ..., -1, 0 precede the first week; weeks numbered 2, 3,... follow it. Note that the normalized numbering returned by get() may be different. For example, a specific Calendar subclass may designate the week before week 1 of a year as week n of the previous year.

When computing a Date from time fields, some special circumstances may arise: there may be insufficient information to compute the Date (such as only year and month but no day in the month), there may be inconsistent information (such as "Tuesday, July 15, 1996" -- July 15, 1996 is actually a Monday), or the input time might be ambiguous because of time zone transition.

Insufficient information. The calendar will use default information to specify the missing fields. This may vary by calendar; for the Gregorian calendar, the default for a field is the same as that of the start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.

Inconsistent information. If fields conflict, the calendar will give preference to fields set more recently. For example, when determining the day, the calendar will look for one of the following combinations of fields. The most recent combination, as determined by the most recently set single field, will be used.

MONTH + DAY_OF_MONTH
MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
DAY_OF_YEAR
DAY_OF_WEEK + WEEK_OF_YEAR
For the time of day:
HOUR_OF_DAY
AM_PM + HOUR

Ambiguous Wall Clock Time. When time offset from UTC has changed, it produces an ambiguous time slot around the transition. For example, many US locations observe daylight saving time. On the date switching to daylight saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on the date. When the input wall time fall into this missing time slot, the ICU Calendar resolves the time using the UTC offset before the transition by default. In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist), so the final result will be 2:30 AM daylight time.

On the date switching back to standard time, wall clock time is moved back one hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this case, the ICU Calendar resolves the time using the UTC offset after the transition by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.

Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs setRepeatedWallTimeOption(int) and setSkippedWallTimeOption(int). These methods are available in ICU 49 or later versions.

Note

for some non-Gregorian calendars, different fields may be necessary for complete disambiguation. For example, a full specification of the historial Arabic astronomical calendar requires year, month, day-of-month and day-of-week in some cases.

Note: There are certain possible ambiguities in interpretation of certain singular times, which are resolved in the following ways:

  1. 24:00:00 "belongs" to the following day. That is, 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
  2. Although historically not precise, midnight also belongs to "am", and noon belongs to "pm", so on the same day, 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm

The date or time format strings are not part of the definition of a calendar, as those must be modifiable or overridable by the user at runtime. Use DateFormat to format dates.

Field manipulation methods

Calendar fields can be changed using three methods: set(), add(), and roll().

set(f, value) changes field f to value. In addition, it sets an internal member variable to indicate that field f has been changed. Although field f is changed immediately, the calendar's milliseconds is not recomputed until the next call to get(), getTime(), or getTimeInMillis() is made. Thus, multiple calls to set() do not trigger multiple, unnecessary computations. As a result of changing a field using set(), other fields may also change, depending on the field, the field value, and the calendar system. In addition, get(f) will not necessarily return value after the fields have been recomputed. The specifics are determined by the concrete calendar class.

Example: Consider a GregorianCalendar originally set to August 31, 1999. Calling set(Calendar.MONTH, Calendar.SEPTEMBER) sets the calendar to September 31, 1999. This is a temporary internal representation that resolves to October 1, 1999 if getTime()is then called. However, a call to set(Calendar.DAY_OF_MONTH, 30) before the call to getTime() sets the calendar to September 30, 1999, since no recomputation occurs after set() itself.

add(f, delta) adds delta to field f. This is equivalent to calling set(f, get(f) + delta) with two adjustments:

Add rule 1. The value of field f after the call minus the value of field f before the call is delta, modulo any overflow that has occurred in field f. Overflow occurs when a field value exceeds its range and, as a result, the next larger field is incremented or decremented and the field value is adjusted back into its range.

Add rule 2. If a smaller field is expected to be invariant, but   it is impossible for it to be equal to its prior value because of changes in its minimum or maximum after field f is changed, then its value is adjusted to be as close as possible to its expected value. A smaller field represents a smaller unit of time. HOUR is a smaller field than DAY_OF_MONTH. No adjustment is made to smaller fields that are not expected to be invariant. The calendar system determines what fields are expected to be invariant.

In addition, unlike set(), add() forces an immediate recomputation of the calendar's milliseconds and all fields.

Example: Consider a GregorianCalendar originally set to August 31, 1999. Calling add(Calendar.MONTH, 13) sets the calendar to September 30, 2000. Add rule 1 sets the MONTH field to September, since adding 13 months to August gives September of the next year. Since DAY_OF_MONTH cannot be 31 in September in a GregorianCalendar, add rule 2 sets the DAY_OF_MONTH to 30, the closest possible value. Although it is a smaller field, DAY_OF_WEEK is not adjusted by rule 2, since it is expected to change when the month changes in a GregorianCalendar.

roll(f, delta) adds delta to field f without changing larger fields. This is equivalent to calling add(f, delta) with the following adjustment:

Roll rule. Larger fields are unchanged after the call. A larger field represents a larger unit of time. DAY_OF_MONTH is a larger field than HOUR.

Example: Consider a GregorianCalendar originally set to August 31, 1999. Calling roll(Calendar.MONTH, 8) sets the calendar to April 30, 1999. Add rule 1 sets the MONTH field to April. Using a GregorianCalendar, the DAY_OF_MONTH cannot be 31 in the month April. Add rule 2 sets it to the closest possible value, 30. Finally, the roll rule maintains the YEAR field value of 1999.

Example: Consider a GregorianCalendar originally set to Sunday June 6, 1999. Calling roll(Calendar.WEEK_OF_MONTH, -1) sets the calendar to Tuesday June 1, 1999, whereas calling add(Calendar.WEEK_OF_MONTH, -1) sets the calendar to Sunday May 30, 1999. This is because the roll rule imposes an additional constraint: The MONTH must not change when the WEEK_OF_MONTH is rolled. Taken together with add rule 1, the resultant date must be between Tuesday June 1 and Saturday June 5. According to add rule 2, the DAY_OF_WEEK, an invariant when changing the WEEK_OF_MONTH, is set to Tuesday, the closest possible value to Sunday (where Sunday is the first day of the week).

Usage model. To motivate the behavior of add() and roll(), consider a user interface component with increment and decrement buttons for the month, day, and year, and an underlying GregorianCalendar. If the interface reads January 31, 1999 and the user presses the month increment button, what should it read? If the underlying implementation uses set(), it might read March 3, 1999. A better result would be February 28, 1999. Furthermore, if the user presses the month increment button again, it should read March 31, 1999, not March 28, 1999. By saving the original date and using either add() or roll(), depending on whether larger fields should be affected, the user interface can behave as most users will intuitively expect.

Note

You should always use roll and add rather than attempting to perform arithmetic operations directly on the fields of a Calendar. It is quite possible for Calendar subclasses to have fields with non-linear behavior, for example missing months or days during non-leap years. The subclasses' add and roll methods will take this into account, while simple arithmetic manipulations may give invalid results.

Calendar Architecture in ICU4J

Recently the implementation of Calendar has changed significantly in order to better support subclassing. The original Calendar class was designed to support subclassing, but it had only one implemented subclass, GregorianCalendar. With the implementation of several new calendar subclasses, including the BuddhistCalendar, ChineseCalendar, HebrewCalendar, IslamicCalendar, and JapaneseCalendar, the subclassing API has been reworked thoroughly. This section details the new subclassing API and other ways in which com.ibm.icu.util.Calendar differs from java.util.Calendar.

Changes

Overview of changes between the classic Calendar architecture and the new architecture.

Subclass API

The original Calendar API was based on the experience of implementing a only a single subclass, GregorianCalendar. As a result, all of the subclassing kinks had not been worked out. The new subclassing API has been refined based on several implemented subclasses. This includes methods that must be overridden and methods for subclasses to call. Subclasses no longer have direct access to fields and stamp. Instead, they have new API to access these. Subclasses are able to allocate the fields array through a protected framework method; this allows subclasses to specify additional fields.

More functionality has been moved into the base class. The base class now contains much of the computational machinery to support the Gregorian calendar. This is based on two things: (1) Many calendars are based on the Gregorian calendar (such as the Buddhist and Japanese imperial calendars). (2) All calendars require basic Gregorian support in order to handle timezone computations.

Common computations have been moved into Calendar. Subclasses no longer compute the week related fields and the time related fields. These are commonly handled for all calendars by the base class.

Subclass computation of time => fields

The ERA, YEAR, EXTENDED_YEAR, MONTH, DAY_OF_MONTH, and DAY_OF_YEAR fields are computed by the subclass, based on the Julian day. All other fields are computed by Calendar.

Subclass computation of fields => time

The interpretation of most field values is handled entirely by Calendar. Calendar determines which fields are set, which are not, which are set more recently, and so on. In addition, Calendar handles the computation of the time from the time fields and handles the week-related fields. The only thing the subclass must do is determine the extended year, based on the year fields, and then, given an extended year and a month, it must return a Julian day number.

Other methods

Normalized behavior

The behavior of certain fields has been made consistent across all calendar systems and implemented in Calendar.

Supported range

The allowable range of Calendar has been narrowed. GregorianCalendar used to attempt to support the range of dates with millisecond values from Long.MIN_VALUE to Long.MAX_VALUE. This introduced awkward constructions (hacks) which slowed down performance. It also introduced non-uniform behavior at the boundaries. The new Calendar protocol specifies the maximum range of supportable dates as those having Julian day numbers of -0x7F000000 to +0x7F000000. This corresponds to years from ~5,800,000 BCE to ~5,800,000 CE. Programmers should use the protected constants in Calendar to specify an extremely early or extremely late date.

General notes

Author
Mark Davis, Deborah Goldsmith, Chen-Lieh Huang, Alan Liu, Laura Werner
ICU Status
Stable since ICU 2.0.
See Also
Date, GregorianCalendar, TimeZone, DateFormat

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Calendar.FormatConfiguration

Deprecated This API is ICU internal only.
An instance of FormatConfiguration represents calendar specific date format configuration and used for calling the ICU private SimpleDateFormat factory method.
pack-priv static class
public static class
Calendar.WeekData

Simple, immutable struct-like class for access to the CLDR week data.

private static class

Field Summary

Modifier and TypeField and Description
private ULocale
actualLocale

The locale containing data used to construct this object, or null.

public static final int
AM

Value of the AM_PM field indicating the period of the day from midnight to just before noon.

public static final int
AM_PM

Field number for get and set indicating whether the HOUR is before or after noon.

public static final int
APRIL

Value of the MONTH field indicating the fourth month of the year.

private transient boolean
areAllFieldsSet

True if all fields have been set.

private transient boolean
areFieldsSet

True if fields[] are in sync with the currently set time.

private transient boolean
areFieldsVirtuallySet

True if all fields have been virtually set, but have not yet been computed.

public static final int
AUGUST

Value of the MONTH field indicating the eighth month of the year.

protected static final int
BASE_FIELD_COUNT

The number of fields defined by this class.

public static final int
DATE

Field number for get and set indicating the day of the month.

pack-priv static final int[][][]
public static final int
DAY_OF_MONTH

Field number for get and set indicating the day of the month.

public static final int
DAY_OF_WEEK

Field number for get and set indicating the day of the week.

public static final int
DAY_OF_WEEK_IN_MONTH

Field number for get and set indicating the ordinal number of the day of the week within the current month.

public static final int
DAY_OF_YEAR

Field number for get and set indicating the day number within the current year.

public static final int
DECEMBER

Value of the MONTH field indicating the twelfth month of the year.

private static final String[]
private static final String[]
public static final int
pack-priv static final int[][][]
public static final int
DST_OFFSET

Field number for get and set indicating the daylight savings offset in milliseconds.

protected static final int
EPOCH_JULIAN_DAY

The Julian day of the epoch, that is, January 1, 1970 on the Gregorian calendar.

public static final int
ERA

Field number for get and set indicating the era, e.g., AD or BC in the Julian calendar.

public static final int
public static final int
FEBRUARY

Value of the MONTH field indicating the second month of the year.

private static final int
private static final String[]
private transient int[]
fields

The field values for the currently set time for this calendar.

private static final int[]
FIND_ZONE_TRANSITION_TIME_UNITS

The time units used by findPreviousZoneTransitionTime(TimeZone, int, long, long) for optimizing transition time binary search.

private int
firstDayOfWeek

The first day of the week, with possible values SUNDAY, MONDAY, etc. This is a locale-dependent value.

public static final int
FRIDAY

Value of the DAY_OF_WEEK field indicating Friday.

protected static final int
GREATEST_MINIMUM

Limit type for getLimit() and handleGetLimit() indicating the greatest minimum value that a field can take.

private static final int[][]
private transient int
gregorianDayOfMonth

The Gregorian day of the month, as computed by computeGregorianFields() and returned by getGregorianDayOfMonth().

private transient int
gregorianDayOfYear

The Gregorian day of the year, as computed by computeGregorianFields() and returned by getGregorianDayOfYear().

private transient int
gregorianMonth

The Gregorian month, as computed by computeGregorianFields() and returned by getGregorianMonth().

private transient int
gregorianYear

The Gregorian year, as computed by computeGregorianFields() and returned by getGregorianYear().

private static String[]
public static final int
HOUR

Field number for get and set indicating the hour of the morning or afternoon.

public static final int
HOUR_OF_DAY

Field number for get and set indicating the hour of the day.

protected static final int
INTERNALLY_SET

Value of the time stamp stamp[] indicating that a field has been set via computations from the time or from other fields.

private transient int
internalSetMask

Bitmask for internalSet() defining which fields may legally be set by subclasses.

public static final int
private transient boolean
isTimeSet

True if then the value of time is valid.

protected static final int
JAN_1_1_JULIAN_DAY

The Julian day of the Gregorian epoch, that is, January 1, 1 on the Gregorian calendar.

public static final int
JANUARY

Value of the MONTH field indicating the first month of the year.

public static final int
public static final int
JULY

Value of the MONTH field indicating the seventh month of the year.

public static final int
JUNE

Value of the MONTH field indicating the sixth month of the year.

protected static final int
LEAST_MAXIMUM

Limit type for getLimit() and handleGetLimit() indicating the least maximum value that a field can take.

private boolean
lenient

True if this calendar allows out-of-range field values during computation of time from fields[].

private static final int[][]
public static final int
MARCH

Value of the MONTH field indicating the third month of the year.

protected static final Date
MAX_DATE

The maximum supported Date.

protected static final int
MAX_FIELD_COUNT

The maximum number of fields possible.

private static final int
MAX_HOURS

The maximum supported hours for millisecond calculations

protected static final int
MAX_JULIAN

The maximum supported Julian day.

protected static final long
MAX_MILLIS

The maximum supported epoch milliseconds.

protected static final int
MAXIMUM

Limit type for getLimit() and handleGetLimit() indicating the maximum value that a field can take (greatest maximum).

public static final int
MAY

Value of the MONTH field indicating the fifth month of the year.

public static final int
MILLISECOND

Field number for get and set indicating the millisecond within the second.

public static final int
protected static final Date
MIN_DATE

The minimum supported Date.

protected static final int
MIN_JULIAN

The minimum supported Julian day.

protected static final long
MIN_MILLIS

The minimum supported epoch milliseconds.

private int
minimalDaysInFirstWeek

The number of days required for the first week in a month or year, with possible values from 1 to 7.

protected static final int
MINIMUM

Limit type for getLimit() and handleGetLimit() indicating the minimum value that a field can take (least minimum).

protected static final int
MINIMUM_USER_STAMP

If the time stamp stamp[] has a value greater than or equal to MINIMUM_USER_SET then it has been set by the user via a call to set().

public static final int
MINUTE

Field number for get and set indicating the minute within the hour.

public static final int
MONDAY

Value of the DAY_OF_WEEK field indicating Monday.

public static final int
MONTH

Field number for get and set indicating the month.

pack-priv static final int[][][]
private transient int
nextStamp

The next available value for stamp[], an internal array.

public static final int
NOVEMBER

Value of the MONTH field indicating the eleventh month of the year.

public static final int
OCTOBER

Value of the MONTH field indicating the tenth month of the year.

protected static final long
ONE_DAY

The number of milliseconds in one day.

protected static final int
ONE_HOUR

The number of milliseconds in one hour.

protected static final int
ONE_MINUTE

The number of milliseconds in one minute.

protected static final int
ONE_SECOND

The number of milliseconds in one second.

protected static final long
ONE_WEEK

The number of milliseconds in one week.

public static final int
private static final ICUCache<String, Calendar.PatternData>
public static final int
PM

Value of the AM_PM field indicating the period of the day from noon to just before midnight.

private static final char
private int
repeatedWallTime

Option used when the specified wall time occurs multiple times.

protected static final int
RESOLVE_REMAP

Value to OR against resolve table field values for remapping.

public static final int
SATURDAY

Value of the DAY_OF_WEEK field indicating Saturday.

public static final int
SECOND

Field number for get and set indicating the second within the minute.

public static final int
SEPTEMBER

Value of the MONTH field indicating the ninth month of the year.

private static final long
serialVersionUID

The version of the serialized data on the stream.

private int
skippedWallTime

Option used when the specified wall time does not exist.

private transient int[]
stamp

Pseudo-time-stamps which specify when each field was set.

private static int
public static final int
SUNDAY

Value of the DAY_OF_WEEK field indicating Sunday.

public static final int
THURSDAY

Value of the DAY_OF_WEEK field indicating Thursday.

private long
time

The currently set time for this calendar, expressed in milliseconds after January 1, 1970, 0:00:00 GMT.

private static final String[]
public static final int
TUESDAY

Value of the DAY_OF_WEEK field indicating Tuesday.

public static final int
UNDECIMBER

Value of the MONTH field indicating the thirteenth month of the year.

protected static final int
UNSET

Value of the time stamp stamp[] indicating that a field has not been set since the last call to clear().

private ULocale
validLocale

The most specific locale containing any resource data, or null.

public static final int
public static final int
public static final int
public static final int
WEDNESDAY

Value of the DAY_OF_WEEK field indicating Wednesday.

private static final Calendar.WeekDataCache
public static final int
WEEK_OF_MONTH

Field number for get and set indicating the week number within the current month.

public static final int
WEEK_OF_YEAR

Field number for get and set indicating the week number within the current year.

public static final int
public static final int
public static final int
public static final int
private int
weekendCease

Day of the week when the weekend stops in this calendar's locale.

private int
weekendCeaseMillis

Milliseconds after midnight at which the weekend stops on the day of the week weekendCease.

private int
weekendOnset

First day of the weekend in this calendar's locale.

private int
weekendOnsetMillis

Milliseconds after midnight at which the weekend starts on the day of the week weekendOnset.

public static final int
YEAR

Field number for get and set indicating the year.

public static final int
private TimeZone
zone

The TimeZone used by this calendar.

public static final int
ZONE_OFFSET

Field number for get and set indicating the raw offset from GMT in milliseconds.

Constructor Summary

AccessConstructor and Description
protected
Calendar()

Constructs a Calendar with the default time zone and the default FORMAT locale.

protected
Calendar(TimeZone
the time zone to use
zone
,
Locale
the locale for the week data
aLocale
)

Constructs a calendar with the specified time zone and locale.

protected
Calendar(TimeZone
the time zone to use
zone
,
ULocale
the ulocale for the week data
locale
)

Constructs a calendar with the specified time zone and locale.

Method Summary

Modifier and TypeMethod and Description
public void
add(int
the time field.
field
,
int
the amount to add to the field.
amount
)

Add a signed amount to a specified field, using this calendar's rules.

public boolean

Returns:

true if the current time of this Calendar is after the time of Calendar when; false otherwise.
after
(Object
the Calendar to be compared with this Calendar.
when
)

Compares the time field records.

public boolean

Returns:

true if the current time of this Calendar is before the time of Calendar when; false otherwise.
before
(Object
the Calendar to be compared with this Calendar.
when
)

Compares the time field records.

public final void
clear()

Clears the values of all the time fields.

public final void
clear(int
the time field to be cleared.
field
)

Clears the value in the given time field.

public Object
clone()

Overrides java.lang.Object.clone.

Overrides Cloneable
private long
compare(Object that)

Returns the difference in milliseconds between the moment this calendar is set to and the moment the given calendar or Date object is set to.

public int

Returns:

0 if the time represented by this Calendar is equal to the time represented by that Calendar, a value less than 0 if the time represented by this is before the time represented by that, and a value greater than 0 if the time represented by this is after the time represented by that.
compareTo
(Calendar
the Calendar to compare to this.
that
)

Implements java.lang.Comparable.compareTo.

Compares the times (in millis) represented by two Calendar objects.
protected void
complete()

Fills in any unset fields in the time field list.

protected void
computeFields()

Converts the current millisecond time value time to field values in fields[].

private final void
computeGregorianAndDOWFields(int julianDay)

Compute the Gregorian calendar year, month, and day of month from the given Julian day.

protected final void
computeGregorianFields(int julianDay)

Compute the Gregorian calendar year, month, and day of month from the Julian day.

protected int

Returns:

the Julian day number of the day before the first day of the given month in the given extended year
computeGregorianMonthStart
(int
extended Gregorian year
year
,
int
zero-based Gregorian month
month
)

Compute the Julian day of a month of the Gregorian calendar.

protected int
computeJulianDay()

Compute the Julian day number as specified by this calendar's fields.

protected int
computeMillisInDay()

Deprecated ICU 60
Compute the milliseconds in the day from the fields.
protected long
computeMillisInDayLong()

Deprecated This API is ICU internal only.
Compute the milliseconds in the day from the fields.
protected void
computeTime()

Converts the current field values in fields[] to the millisecond time value time.

private final void
computeWeekFields()

Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH, DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR, DAY_OF_WEEK, and DAY_OF_YEAR.

protected int

Returns:

total zone offset (raw + DST) for the given moment
computeZoneOffset
(long
milliseconds of the date fields (local midnight millis)
millis
,
int
milliseconds of the time fields; may be out or range.
millisInDay
)

Deprecated ICU 60
This method can assume EXTENDED_YEAR has been set.
protected int

Returns:

total zone offset (raw + DST) for the given moment
computeZoneOffset
(long
milliseconds of the date fields (local midnight millis)
millis
,
long
milliseconds of the time fields
millisInDay
)

Deprecated This API is ICU internal only.
This method can assume EXTENDED_YEAR has been set.
private static Calendar
public boolean

Returns:

true if the objects are the same; false otherwise.
equals
(Object
the object to compare with.
obj
)

Overrides java.lang.Object.equals.

Compares this calendar to the specified object.
private static String
expandOverride(String pattern, String override)

public int

Returns:

the difference, either positive or negative, between this calendar's time and when, in terms of field.
fieldDifference
(Date
the date to compare this calendar's time to
when
,
int
the field in which to compute the result
field
)

ICU

protected String
fieldName(int field)

Returns a string name for a field, for debugging and exceptions.

private static Long

Returns:

The time of the previous zone transition, or null if not available.
findPreviousZoneTransitionTime
(TimeZone
The time zone.
tz
,
int
The zone offset at upper
upperOffset
,
long
The upper bound, inclusive.
upper
,
long
The lower bound, exclusive.
lower
)

Implementing binary search for zone transition detection, used by getPreviousZoneTransitionTime(TimeZone, long, long)

private static int
firstIslamicStartYearFromGrego(int year)

utility function for setRelatedYear

protected static final long

Returns:

the floor of the quotient.
floorDivide
(long
the numerator
numerator
,
long
a divisor which must be > 0
denominator
)

Divide two long integers, returning the floor of the quotient.

protected static final int

Returns:

the floor of the quotient.
floorDivide
(int
the numerator
numerator
,
int
a divisor which must be > 0
denominator
)

Divide two integers, returning the floor of the quotient.

protected static final int

Returns:

the floor of the quotient.
floorDivide
(int
the numerator
numerator
,
int
a divisor which must be > 0
denominator
,
int[]
an array of at least one element in which the value numerator mod denominator is returned. Unlike numerator % denominator, this will always be non-negative.
remainder
)

Divide two integers, returning the floor of the quotient, and the modulus remainder.

protected static final int

Returns:

the floor of the quotient.
floorDivide
(long
the numerator
numerator
,
int
a divisor which must be > 0
denominator
,
int[]
an array of at least one element in which the value numerator mod denominator is returned. Unlike numerator % denominator, this will always be non-negative.
remainder
)

Divide two integers, returning the floor of the quotient, and the modulus remainder.

private static DateFormat
formatHelper(Calendar cal, ULocale loc, int dateStyle, int timeStyle)

public final int

Returns:

the value for the given time field.
get
(int
the given time field.
field
)

Returns the value for a given time field.

private int
getActualHelper(int field, int startValue, int endValue)

public int

Returns:

the maximum of the given field for the current date of this calendar
getActualMaximum
(int
the field whose maximum is desired
field
)

Returns the maximum value that this field could have, given the current date.

public int

Returns:

the minimum of the given field for the current date of this calendar
getActualMinimum
(int
the field whose actual minimum value is desired.
field
)

Returns the minimum value that this field could have, given the current date.

public static Locale[]

Returns:

the list of locales for which Calendars are installed.
getAvailableLocales
()

Returns the list of locales for which Calendars are installed.

public static ULocale[]

Returns:

the list of locales for which Calendars are installed.
getAvailableULocales
()

ICU

private static CalType
public static String
getDateAtTimePattern(Calendar cal, ULocale uLocale, int dateStyle)

Deprecated This API is ICU internal only.
public DateFormat
getDateTimeFormat(int dateStyle, int timeStyle, Locale loc)

ICU

public DateFormat
getDateTimeFormat(int dateStyle, int timeStyle, ULocale loc)

ICU

public static String
getDateTimePattern(Calendar cal, ULocale uLocale, int dateStyle)

Deprecated This API is ICU internal only.
public int

Returns:

either WEEKDAY, WEEKEND, WEEKEND_ONSET, or WEEKEND_CEASE
getDayOfWeekType
(int
either SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, or SATURDAY
dayOfWeek
)

ICU

protected int

Returns:

the default day of the month
getDefaultDayInMonth
(int
the extendedYear, as returned by handleGetExtendedYear
extendedYear
,
int
the month, as returned by getDefaultMonthInYear
month
)

Subclasses may override this.

protected int

Returns:

the default month
getDefaultMonthInYear
(int
the extendedYear, as returned by handleGetExtendedYear
extendedYear
)

Subclasses may override this.

public String
getDisplayName(Locale loc)

Returns the name of this calendar in the language of the given locale.

public String
getDisplayName(ULocale loc)

Returns the name of this calendar in the language of the given locale.

public final int
protected int[][][]
getFieldResolutionTable()

Returns the field resolution array for this calendar.

public int

Returns:

the first day of the week, where 1 = SUNDAY and 7 = SATURDAY.
getFirstDayOfWeek
()

Returns what the first day of the week is, where 1 = SUNDAY and 7 = SATURDAY.

public final int

Returns:

the highest minimum value for the given time field.
getGreatestMinimum
(int
the given time field.
field
)

Returns the highest minimum value for the given field if varies.

protected final int
getGregorianDayOfMonth()

Returns the day of month (1-based) on the Gregorian calendar as computed by computeGregorianFields().

protected final int
getGregorianDayOfYear()

Returns the day of year (1-based) on the Gregorian calendar as computed by computeGregorianFields().

protected final int
getGregorianMonth()

Returns the month (0-based) on the Gregorian calendar as computed by computeGregorianFields().

protected final int
getGregorianYear()

Returns the extended year on the Gregorian calendar as computed by computeGregorianFields().

private Long

Returns:

The time of the previous transition, or null if not found.
getImmediatePreviousZoneTransition
(long
The base time, inclusive.
base
)

Find the previous zone transition near the given time.

public static Calendar

Returns:

a Calendar.
getInstance
()

Returns a calendar using the default time zone and locale.

public static Calendar

Returns:

a Calendar.
getInstance
(TimeZone
the time zone to use
zone
)

Returns a calendar using the specified time zone and default locale.

public static Calendar

Returns:

a Calendar.
getInstance
(Locale
the locale for the week data
aLocale
)

Returns a calendar using the default time zone and specified locale.

public static Calendar

Returns:

a Calendar.
getInstance
(ULocale
the ulocale for the week data
locale
)

Returns a calendar using the default time zone and specified locale.

public static Calendar

Returns:

a Calendar.
getInstance
(TimeZone
the time zone to use
zone
,
Locale
the locale for the week data
aLocale
)

Returns a calendar with the specified time zone and locale.

public static Calendar

Returns:

a Calendar.
getInstance
(TimeZone
the time zone to use
zone
,
ULocale
the ulocale for the week data
locale
)

Returns a calendar with the specified time zone and locale.

private static Calendar
public static final String[]

Returns:

an array of string values for the given key and the locale.
getKeywordValuesForLocale
(String
one of the keys supported by this service. For now, only "calendar" is supported.
key
,
ULocale
the locale
locale
,
boolean
if set to true it will return only commonly used values with the given locale in preferred order. Otherwise, it will return all the available values for the locale.
commonlyUsed
)

ICU

public final int

Returns:

the lowest maximum value for the given time field.
getLeastMaximum
(int
the given time field.
field
)

Returns the lowest maximum value for the given field if varies.

protected int
getLimit(int
the field, from 0..getFieldCount()-1
field
,
int
the type specifier for the limit
limitType
)

Returns a limit for a field.

public final ULocale

Returns:

the information specified by type, or null if this object was not constructed from locale data.
getLocale
(ULocale.Type type)

ICU

public final int

Returns:

the maximum value for the given time field.
getMaximum
(int
the given time field.
field
)

Returns the maximum value for the given time field.

public int

Returns:

the minimal days required in the first week of the year.
getMinimalDaysInFirstWeek
()

Returns what the minimal days required in the first week of the year are.

public final int

Returns:

the minimum value for the given time field.
getMinimum
(int
the given time field.
field
)

Returns the minimum value for the given time field.

private static Calendar.PatternData

Returns:

PatternData object for this locale and calendarType.
getPatternData
(ULocale
Locale to retrieve.
locale
,
String
Calendar type to retrieve. If not found will fallback to gregorian.
calType
)

Retrieves the DateTime patterns and overrides from the resource bundle and generates a new PatternData object.

private static Long

Returns:

The time of the previous zone transition, or null if not available.
getPreviousZoneTransitionTime
(TimeZone
The time zone.
tz
,
long
The base time, inclusive.
base
,
long
The range of time evaluated.
duration
)

Find the previous zone transition within the specified duration.

private static String
public final int
getRelatedYear()

Deprecated This API is ICU internal only.
public int

Returns:

the behavior for handling repeating wall time, either WALLTIME_FIRST or WALLTIME_LAST.
getRepeatedWallTimeOption
()

ICU

public int

Returns:

the behavior for handling skipped wall time, one of WALLTIME_FIRST, WALLTIME_LAST and WALLTIME_NEXT_VALID.
getSkippedWallTimeOption
()

ICU

protected final int
getStamp(int field)

Returns the timestamp of a field.

public String

Returns:

One of 25 possible strings in {"M01".."M13", "M01L".."M12L"}.
getTemporalMonthCode
()

Gets The Temporal monthCode value corresponding to the month for the date.

public final Date

Returns:

the current time.
getTime
()

Returns this Calendar's current time.

public long

Returns:

the current time as UTC milliseconds from the epoch.
getTimeInMillis
()

Returns this Calendar's current time as a long.

public TimeZone

Returns:

the time zone object associated with this calendar.
getTimeZone
()

Returns the time zone.

public String

Returns:

legacy calendar type name string
getType
()

ICU

public Calendar.WeekData

Returns:

the WeekData for this calendar.
getWeekData
()

ICU

public static Calendar.WeekData

Returns:

the WeekData for the input region. It is never null.
getWeekDataForRegion
(String
The input region. The results are undefined if the region code is not valid.
region
)

ICU

private static Calendar.WeekData
public int

Returns:

the milliseconds after midnight at which the weekend begins or ends
getWeekendTransition
(int
either SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, or SATURDAY
dayOfWeek
)

ICU

protected static final int

Returns:

the number of days in the given month
gregorianMonthLength
(int
the extended year
y
,
int
the 0-based month number
m
)

Returns the length of a month of the Gregorian calendar.

protected static final int

Returns:

the number of days in the month previous to the given month
gregorianPreviousMonthLength
(int
the extended year
y
,
int
the 0-based month number
m
)

Returns the length of a previous month of the Gregorian calendar.

private static int
gregoYearFromIslamicStart(int year)

utility function for getRelatedYear

protected void
handleComputeFields(int julianDay)

Subclasses may override this method to compute several fields specific to each calendar system.

protected int
handleComputeJulianDay(int bestField)

Subclasses may override this.

protected abstract int

Returns:

the Julian day number of the day before the first day of the given month and year
handleComputeMonthStart
(int
the extended year
eyear
,
int
the zero-based month, or 0 if useMonth is false
month
,
boolean
if false, compute the day before the first day of the given year, otherwise, compute the day before the first day of the given month
useMonth
)

Returns the Julian day number of day before the first day of the given month in the given extended year.

protected int[]
handleCreateFields()

Subclasses that use additional fields beyond those defined in Calendar should override this method to return an int[] array of the appropriate length.

protected DateFormat

Returns:

a DateFormat appropriate to this calendar
handleGetDateFormat
(String
the pattern, specific to the DateFormat subclass
pattern
,
Locale
the locale for which the symbols should be drawn
locale
)

Creates a DateFormat appropriate to this calendar.

protected DateFormat

Returns:

a DateFormat appropriate to this calendar
handleGetDateFormat
(String
the pattern, specific to the DateFormat subclass
pattern
,
String
The override string. A numbering system override string can take one of the following forms: 1). If just a numbering system name is specified, it applies to all numeric fields in the date format pattern. 2). To specify an alternate numbering system on a field by field basis, use the field letters from the pattern followed by an = sign, followed by the numbering system name. For example, to specify that just the year be formatted using Hebrew digits, use the override "y=hebr". Multiple overrides can be specified in a single string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using Thai digits for the month and Devanagari digits for the year.
override
,
Locale
the locale for which the symbols should be drawn
locale
)

Creates a DateFormat appropriate to this calendar.

protected DateFormat

Returns:

a DateFormat appropriate to this calendar
handleGetDateFormat
(String
the pattern, specific to the DateFormat subclass
pattern
,
ULocale
the locale for which the symbols should be drawn
locale
)

Creates a DateFormat appropriate to this calendar.

protected DateFormat

Returns:

a DateFormat appropriate to this calendar
handleGetDateFormat
(String
the pattern, specific to the DateFormat subclass
pattern
,
String override, ULocale
the locale for which the symbols should be drawn
locale
)

Creates a DateFormat appropriate to this calendar.

protected abstract int

Returns:

the extended year
handleGetExtendedYear
()

Returns the extended year defined by the current fields.

protected abstract int
handleGetLimit(int
one of the above field numbers
field
,
int
one of MINIMUM, GREATEST_MINIMUM, LEAST_MAXIMUM, or MAXIMUM
limitType
)

Subclass API for defining limits of different types.

protected int
handleGetMonthLength(int extendedYear, int month)

Returns the number of days in the given month of the given extended year of this calendar system.

protected int
handleGetYearLength(int eyear)

Returns the number of days in the given extended year of this calendar system.

public int

Returns:

a hash code value for this object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this calendar.
public boolean

Returns:

true if this calendar has a default century.
haveDefaultCentury
()

Deprecated This API is ICU internal only.
Returns if two digit representation of year in this calendar type customarily implies a default century (i.e. 03 -> 2003).
private void
public boolean

Returns:

true if the date in the fields is in a Temporal proposal defined leap year. False otherwise.
inTemporalLeapYear
()

ICU

protected final int

Returns:

the value for the given time field.
internalGet
(int
the given time field.
field
)

Returns the value for a given time field.

protected final int

Returns:

the value for the given time field of defaultValue if the field is unset
internalGet
(int
the given time field.
field
,
int
value to return if field is not set
defaultValue
)

Returns the value for a given time field, or return the given default value if the field is not set.

protected int

Returns:

the value for the given time field.
internalGetMonth
()

Deprecated This API is ICU internal only.
Use this function instead of internalGet(MONTH).
protected int

Returns:

the value for the MONTH.
internalGetMonth
(int
a default value used if the MONTH and ORDINAL_MONTH are both unset.
defaultValue
)

Deprecated This API is ICU internal only.
Use this function instead of internalGet(MONTH, defaultValue).
protected final long
internalGetTimeInMillis()

Returns the current milliseconds without recomputing.

protected final void
internalSet(int field, int value)

Set a field to a value.

public boolean
isEquivalentTo(Calendar
the Calendar to be compared with this Calendar
other
)

ICU

protected static final boolean

Returns:

true if the given year is a leap year; false otherwise.
isGregorianLeapYear
(int
the given year.
year
)

Determines if the given year is a leap year.

public boolean
isLenient()

Tell whether date/time interpretation is to be lenient.

public final boolean

Returns:

true if the given time field has a value set; false otherwise.
isSet
(int field)

Determines if the given time field has a value set.

public boolean

Returns:

true if the given date and time is part of the weekend
isWeekend
(Date
the date and time
date
)

ICU

public boolean

Returns:

true if the given date and time is part of the weekend
isWeekend
()

ICU

protected static final int
julianDayToDayOfWeek(int julian)

Returns the day of week, from SUNDAY to SATURDAY, given a Julian day.

protected static final long

Returns:

time as milliseconds.
julianDayToMillis
(int
the given Julian day number.
julian
)

Converts Julian day to time as milliseconds.

private static String
mergeOverrideStrings(String datePattern, String timePattern, String dateOverride, String timeOverride)

protected static final int

Returns:

the Julian day number.
millisToJulianDay
(long
the given milliseconds.
millis
)

Converts time as milliseconds to Julian day.

protected int
newerField(int defaultField, int alternateField)

Returns the field that is newer, either defaultField, or alternateField.

protected int
newestStamp(int first, int last, int bestStampSoFar)

Returns the newest stamp of a given range of fields.

protected void
pinField(int
The calendar field whose value should be pinned.
field
)

Adjust the specified field so that it is within the allowable range for the date to which this calendar is set.

protected void
prepareGetActual(int field, boolean isMinimum)

Prepare this calendar for computing the actual minimum or maximum.

private void
readObject(ObjectInputStream stream)

Reconstitute this object from a stream (i.e., deserialize it).

private void
protected int
resolveFields(int[][][] precedenceTable)

Given a precedence table, return the newest field combination in the table, or -1 if none is found.

public final void
roll(int
the calendar field to roll.
field
,
boolean
indicates if the value of the specified time field is to be rolled up or rolled down. Use true if rolling up, false otherwise.
up
)

Rolls (up/down) a single unit of time on the given field.

public void
roll(int
the calendar field to roll.
field
,
int
the amount by which the field should be rolled.
amount
)

Rolls (up/down) a specified amount time on the given field.

public final void
set(int
the given time field.
field
,
int
the value to be set for the given time field.
value
)

Sets the time field with the given value.

public final void
set(int
the value used to set the YEAR time field.
year
,
int
the value used to set the MONTH time field. Month value is 0-based. e.g., 0 for January.
month
,
int
the value used to set the DATE time field.
date
)

Sets the values for the fields year, month, and date.

public final void
set(int
the value used to set the YEAR time field.
year
,
int
the value used to set the MONTH time field. Month value is 0-based. e.g., 0 for January.
month
,
int
the value used to set the DATE time field.
date
,
int
the value used to set the HOUR_OF_DAY time field.
hour
,
int
the value used to set the MINUTE time field.
minute
)

Sets the values for the fields year, month, date, hour, and minute.

public final void
set(int
the value used to set the YEAR time field.
year
,
int
the value used to set the MONTH time field. Month value is 0-based. e.g., 0 for January.
month
,
int
the value used to set the DATE time field.
date
,
int
the value used to set the HOUR_OF_DAY time field.
hour
,
int
the value used to set the MINUTE time field.
minute
,
int
the value used to set the SECOND time field.
second
)

Sets the values for the fields year, month, date, hour, minute, and second.

private void
public void
setFirstDayOfWeek(int
the given first day of the week, where 1 = SUNDAY and 7 = SATURDAY.
value
)

Sets what the first day of the week is, where 1 = SUNDAY and 7 = SATURDAY.

public void
setLenient(boolean lenient)

Specify whether or not date/time interpretation is to be lenient.

pack-priv final void
setLocale(ULocale
the most specific locale containing any resource data, or null
valid
,
ULocale
the locale containing data used to construct this object, or null
actual
)

Set information about the locales that were used to create this object.

public void
setMinimalDaysInFirstWeek(int
the given minimal days required in the first week of the year.
value
)

Sets what the minimal days required in the first week of the year are.

public final void
setRelatedYear(int year)

Deprecated This API is ICU internal only.
public void
setRepeatedWallTimeOption(int
the behavior for handling repeating wall time, either WALLTIME_FIRST or WALLTIME_LAST.
option
)

ICU

public void
setSkippedWallTimeOption(int
the behavior for handling skipped wall time at positive time zone offset transitions, one of WALLTIME_FIRST, WALLTIME_LAST and WALLTIME_NEXT_VALID.
option
)

ICU

public void
setTemporalMonthCode(String
One of 25 possible strings in {"M01".. "M12", "M13", "M01L", "M12L"}.
temporalMonth
)

Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar.

public final void
setTime(Date
the given Date.
date
)

Sets this Calendar's current time with the given Date.

public void
setTimeInMillis(long
the new time in UTC milliseconds from the epoch.
millis
)

Sets this Calendar's current time from the given long value.

public void
setTimeZone(TimeZone
the given time zone.
value
)

Sets the time zone with the given time zone value.

public Calendar

Returns:

this, for chaining
setWeekData
(Calendar.WeekData
The week data to use
wdata
)

ICU

private void
public String

Returns:

a string representation of this calendar.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this calendar.
private void
updateTime()

Recompute the time and update the status fields isTimeSet and areFieldsSet.

protected void
validateField(int field)

Validate a single field of this calendar.

protected final void
validateField(int field, int min, int max)

Validate a single field of this calendar given its minimum and maximum allowed value.

protected void
validateFields()

Ensure that each field is within its valid range by calling validateField(int) on each field that has been set.

protected int

Returns:

The week number (one-based), or zero if the day falls before the first week because getMinimalDaysInFirstWeek is more than one.
weekNumber
(int
The DAY_OF_YEAR or DAY_OF_MONTH whose week number is desired. Should be 1 for the first day of the period.
desiredDay
,
int
The DAY_OF_YEAR or DAY_OF_MONTH for a day in the period whose DAY_OF_WEEK is specified by the dayOfWeek parameter. Should be 1 for first day of period.
dayOfPeriod
,
int
The DAY_OF_WEEK for the day corresponding to the dayOfPeriod parameter. 1-based with 1=Sunday.
dayOfWeek
)

Returns the week number of a day, within a period.

protected final int

Returns:

The week number (one-based), or zero if the day falls before the first week because getMinimalDaysInFirstWeek is more than one.
weekNumber
(int
The DAY_OF_YEAR or DAY_OF_MONTH whose week number is desired. Should be 1 for the first day of the period.
dayOfPeriod
,
int
The DAY_OF_WEEK for the day corresponding to the dayOfPeriod parameter. 1-based with 1=Sunday.
dayOfWeek
)

Returns the week number of a day, within a period.

private void
writeObject(ObjectOutputStream stream)

Save the state of this object to a stream (i.e., serialize it).

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait