Calendarpublic abstract class Calendar extends Object implements Serializable, Comparable, Cloneable{@code Calendar} is an abstract base class for converting between a
{@code Date} object and a set of integer fields such as
{@code YEAR}, {@code MONTH}, {@code DAY},
{@code HOUR}, and so on. (A {@code Date} object represents a
specific instant in time with millisecond precision. See {@link Date} for
information about the {@code Date} class.)
Subclasses of {@code Calendar} interpret a {@code Date}
according to the rules of a specific calendar system.
Like other locale-sensitive classes, {@code Calendar} provides a class
method, {@code getInstance}, for getting a default instance of
this class for general use. {@code Calendar}'s {@code getInstance} method
returns a calendar whose locale is based on system settings and whose time fields
have been initialized with the current date and time:
Calendar rightNow = Calendar.getInstance()
A {@code 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).
{@code 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 {@code MONTH} == {@code JANUARY} for all calendars.
Other values are defined by the concrete subclass, such as {@code ERA}
and {@code YEAR}. See individual field documentation and subclass
documentation for details.
When a {@code Calendar} is lenient, it accepts a wider
range of field values than it produces. For example, a lenient
{@code GregorianCalendar} interprets {@code MONTH} ==
{@code JANUARY}, {@code DAY_OF_MONTH} == 32 as February 1. A
non-lenient {@code GregorianCalendar} throws an exception when given
out-of-range field settings. When calendars recompute field values for return
by {@code get()}, they normalize them. For example, a
{@code GregorianCalendar} always produces {@code DAY_OF_MONTH}
values between 1 and the length of the month.
{@code 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
{@code Calendar} is constructed. They may also be specified explicitly
through the API.
When setting or getting the {@code WEEK_OF_MONTH} or
{@code WEEK_OF_YEAR} fields, {@code 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
{@code getFirstDayOfWeek()} and containing at least
{@code 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 {@code get()} may
be different. For example, a specific {@code Calendar} subclass may
designate the week before week 1 of a year as week n of the
previous year.
When computing a {@code Date} from time fields, two special
circumstances may arise: there may be insufficient information to compute the
{@code Date} (such as only year and month but no day in the month), or
there may be inconsistent information (such as "Tuesday, July 15, 1996" --
July 15, 1996 is actually a Monday).
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
Note: There are certain possible ambiguities in
interpretation of certain singular times, which are resolved in the following
ways:
- 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 form a sequence of
three consecutive minutes in time.
- Although historically not precise, midnight also belongs to "am", and
noon belongs to "pm", so on the same day, we have 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
{@link java.text.DateFormat} to format dates.
Field manipulation methods
{@code Calendar} fields can be changed using three methods:
{@code set()}, {@code add()}, and {@code roll()}.
{@code set(f, value)} changes field {@code f}
to {@code value}. In addition, it sets an internal member variable to
indicate that field {@code f} has been changed. Although field
{@code f} is changed immediately, the calendar's milliseconds is not
recomputed until the next call to {@code get()},
{@code getTime()}, or {@code getTimeInMillis()} is made. Thus,
multiple calls to {@code set()} do not trigger multiple, unnecessary
computations. As a result of changing a field using {@code set()},
other fields may also change, depending on the field, the field value, and
the calendar system. In addition, {@code get(f)} will not necessarily
return {@code value} after the fields have been recomputed. The
specifics are determined by the concrete calendar class.
Example: Consider a {@code 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 {@code getTime()}is
then called. However, a call to {@code set(Calendar.DAY_OF_MONTH, 30)}
before the call to {@code getTime()} sets the calendar to September
30, 1999, since no recomputation occurs after {@code set()} itself.
{@code add(f, delta)} adds {@code delta} to
field {@code f}. This is equivalent to calling set(f,
get(f) + delta)
with two adjustments:
Add rule 1. The value of field {@code f} after the
call minus the value of field {@code f} before the call is
{@code delta}, modulo any overflow that has occurred in field
{@code 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 {@code 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. {@code HOUR} is a
smaller field than {@code 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 {@code set()}, {@code add()} forces an
immediate recomputation of the calendar's milliseconds and all fields.
Example: Consider a {@code GregorianCalendar} originally
set to August 31, 1999. Calling {@code add(Calendar.MONTH, 13)} sets
the calendar to September 30, 2000. Add rule 1 sets the
{@code MONTH} field to September, since adding 13 months to August
gives September of the next year. Since {@code DAY_OF_MONTH} cannot be
31 in September in a {@code GregorianCalendar}, add rule 2
sets the {@code DAY_OF_MONTH} to 30, the closest possible value.
Although it is a smaller field, {@code DAY_OF_WEEK} is not adjusted by
rule 2, since it is expected to change when the month changes in a
{@code GregorianCalendar}.
{@code roll(f, delta)} adds {@code delta} to
field {@code f} without changing larger fields. This is equivalent to
calling {@code 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. {@code DAY_OF_MONTH} is
a larger field than {@code HOUR}.
Example: Consider a {@code GregorianCalendar} originally
set to August 31, 1999. Calling roll(Calendar.MONTH,
8) sets
the calendar to April 30, 1999. Add rule 1 sets the
{@code MONTH} field to April. Using a {@code GregorianCalendar},
the {@code 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 {@code YEAR} field value of 1999.
Example: Consider a {@code GregorianCalendar} originally
set to Sunday June 6, 1999. Calling
{@code roll(Calendar.WEEK_OF_MONTH, -1)} sets the calendar to Tuesday
June 1, 1999, whereas calling {@code 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 {@code MONTH} must not change
when the {@code 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 {@code DAY_OF_WEEK}, an invariant when
changing the {@code 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 {@code add()}
and {@code roll()}, consider a user interface component with
increment and decrement buttons for the month, day, and year, and an
underlying {@code 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 {@code 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
{@code add()} or {@code 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 {@code roll} and {@code 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. |
Fields Summary |
---|
private static final long | serialVersionUID | protected boolean | areFieldsSetSet to {@code true} when the calendar fields have been set from the time, set to
{@code false} when a field is changed and the fields must be recomputed. | protected int[] | fieldsAn integer array of calendar fields. The length is {@code FIELD_COUNT}. | protected boolean[] | isSetA boolean array. Each element indicates if the corresponding field has
been set. The length is {@code FIELD_COUNT}. | protected boolean | isTimeSetSet to {@code true} when the time has been set, set to {@code false} when a field is
changed and the time must be recomputed. | protected long | timeThe time in milliseconds since January 1, 1970. | transient int | lastTimeFieldSet | transient int | lastDateFieldSet | private boolean | lenient | private int | firstDayOfWeek | private int | minimalDaysInFirstWeek | private TimeZone | zone | public static final int | JANUARYValue of the {@code MONTH} field indicating the first month of the
year. | public static final int | FEBRUARYValue of the {@code MONTH} field indicating the second month of
the year. | public static final int | MARCHValue of the {@code MONTH} field indicating the third month of the
year. | public static final int | APRILValue of the {@code MONTH} field indicating the fourth month of
the year. | public static final int | MAYValue of the {@code MONTH} field indicating the fifth month of the
year. | public static final int | JUNEValue of the {@code MONTH} field indicating the sixth month of the
year. | public static final int | JULYValue of the {@code MONTH} field indicating the seventh month of
the year. | public static final int | AUGUSTValue of the {@code MONTH} field indicating the eighth month of
the year. | public static final int | SEPTEMBERValue of the {@code MONTH} field indicating the ninth month of the
year. | public static final int | OCTOBERValue of the {@code MONTH} field indicating the tenth month of the
year. | public static final int | NOVEMBERValue of the {@code MONTH} field indicating the eleventh month of
the year. | public static final int | DECEMBERValue of the {@code MONTH} field indicating the twelfth month of
the year. | public static final int | UNDECIMBERValue of the {@code MONTH} field indicating the thirteenth month
of the year. Although {@code GregorianCalendar} does not use this
value, lunar calendars do. | public static final int | SUNDAYValue of the {@code DAY_OF_WEEK} field indicating Sunday. | public static final int | MONDAYValue of the {@code DAY_OF_WEEK} field indicating Monday. | public static final int | TUESDAYValue of the {@code DAY_OF_WEEK} field indicating Tuesday. | public static final int | WEDNESDAYValue of the {@code DAY_OF_WEEK} field indicating Wednesday. | public static final int | THURSDAYValue of the {@code DAY_OF_WEEK} field indicating Thursday. | public static final int | FRIDAYValue of the {@code DAY_OF_WEEK} field indicating Friday. | public static final int | SATURDAYValue of the {@code DAY_OF_WEEK} field indicating Saturday. | public static final int | ERAField number for {@code get} and {@code set} indicating the
era, e.g., AD or BC in the Julian calendar. This is a calendar-specific
value; see subclass documentation. | public static final int | YEARField number for {@code get} and {@code set} indicating the
year. This is a calendar-specific value; see subclass documentation. | public static final int | MONTHField number for {@code get} and {@code set} indicating the
month. This is a calendar-specific value. The first month of the year is
{@code JANUARY}; the last depends on the number of months in a
year. | public static final int | WEEK_OF_YEARField number for {@code get} and {@code set} indicating the
week number within the current year. The first week of the year, as
defined by {@code getFirstDayOfWeek()} and
{@code getMinimalDaysInFirstWeek()}, has value 1. Subclasses
define the value of {@code WEEK_OF_YEAR} for days before the first
week of the year. | public static final int | WEEK_OF_MONTHField number for {@code get} and {@code set} indicating the
week number within the current month. The first week of the month, as
defined by {@code getFirstDayOfWeek()} and
{@code getMinimalDaysInFirstWeek()}, has value 1. Subclasses
define the value of {@code WEEK_OF_MONTH} for days before the
first week of the month. | public static final int | DATEField number for {@code get} and {@code set} indicating the
day of the month. This is a synonym for {@code DAY_OF_MONTH}. The
first day of the month has value 1. | public static final int | DAY_OF_MONTHField number for {@code get} and {@code set} indicating the
day of the month. This is a synonym for {@code DATE}. The first
day of the month has value 1. | public static final int | DAY_OF_YEARField number for {@code get} and {@code set} indicating the
day number within the current year. The first day of the year has value
1. | public static final int | DAY_OF_WEEKField number for {@code get} and {@code set} indicating the
day of the week. This field takes values {@code SUNDAY},
{@code MONDAY}, {@code TUESDAY}, {@code WEDNESDAY},
{@code THURSDAY}, {@code FRIDAY}, and
{@code SATURDAY}. | public static final int | DAY_OF_WEEK_IN_MONTHField number for {@code get} and {@code set} indicating the
ordinal number of the day of the week within the current month. Together
with the {@code DAY_OF_WEEK} field, this uniquely specifies a day
within a month. Unlike {@code WEEK_OF_MONTH} and
{@code WEEK_OF_YEAR}, this field's value does not
depend on {@code getFirstDayOfWeek()} or
{@code getMinimalDaysInFirstWeek()}. {@code DAY_OF_MONTH 1}
through {@code 7} always correspond to DAY_OF_WEEK_IN_MONTH
1 ;
{@code 8} through {@code 15} correspond to
{@code DAY_OF_WEEK_IN_MONTH 2}, and so on.
{@code DAY_OF_WEEK_IN_MONTH 0} indicates the week before
{@code DAY_OF_WEEK_IN_MONTH 1}. Negative values count back from
the end of the month, so the last Sunday of a month is specified as
{@code DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1}. Because
negative values count backward they will usually be aligned differently
within the month than positive values. For example, if a month has 31
days, {@code DAY_OF_WEEK_IN_MONTH -1} will overlap
{@code DAY_OF_WEEK_IN_MONTH 5} and the end of {@code 4}. | public static final int | AM_PMField number for {@code get} and {@code set} indicating
whether the {@code HOUR} is before or after noon. E.g., at
10:04:15.250 PM the {@code AM_PM} is {@code PM}. | public static final int | HOURField number for {@code get} and {@code set} indicating the
hour of the morning or afternoon. {@code HOUR} is used for the
12-hour clock. E.g., at 10:04:15.250 PM the {@code HOUR} is 10. | public static final int | HOUR_OF_DAYField number for {@code get} and {@code set} indicating the
hour of the day. {@code HOUR_OF_DAY} is used for the 24-hour
clock. E.g., at 10:04:15.250 PM the {@code HOUR_OF_DAY} is 22. | public static final int | MINUTEField number for {@code get} and {@code set} indicating the
minute within the hour. E.g., at 10:04:15.250 PM the {@code MINUTE}
is 4. | public static final int | SECONDField number for {@code get} and {@code set} indicating the
second within the minute. E.g., at 10:04:15.250 PM the
{@code SECOND} is 15. | public static final int | MILLISECONDField number for {@code get} and {@code set} indicating the
millisecond within the second. E.g., at 10:04:15.250 PM the
{@code MILLISECOND} is 250. | public static final int | ZONE_OFFSETField number for {@code get} and {@code set} indicating the
raw offset from GMT in milliseconds. | public static final int | DST_OFFSETField number for {@code get} and {@code set} indicating the
daylight savings offset in milliseconds. | public static final int | FIELD_COUNTThis is the total number of fields in this calendar. | public static final int | AMValue of the {@code AM_PM} field indicating the period of the day
from midnight to just before noon. | public static final int | PMValue of the {@code AM_PM} field indicating the period of the day
from noon to just before midnight. | private static String[] | fieldNames | private static final ObjectStreamField[] | serialPersistentFields |
Constructors Summary |
---|
protected Calendar()Constructs a {@code Calendar} instance using the default {@code TimeZone} and {@code Locale}. //$NON-NLS-1$ //$NON-NLS-2$
this(TimeZone.getDefault(), Locale.getDefault());
| Calendar(TimeZone timezone)
fields = new int[FIELD_COUNT];
isSet = new boolean[FIELD_COUNT];
areFieldsSet = isTimeSet = false;
setLenient(true);
setTimeZone(timezone);
| protected Calendar(TimeZone timezone, Locale locale)Constructs a {@code Calendar} instance using the specified {@code TimeZone} and {@code Locale}.
this(timezone);
ResourceBundle bundle = Locale.getBundle("Locale", locale); //$NON-NLS-1$
setFirstDayOfWeek(((Integer) bundle.getObject("First_Day")).intValue()); //$NON-NLS-1$
setMinimalDaysInFirstWeek(((Integer) bundle.getObject("Minimal_Days")) //$NON-NLS-1$
.intValue());
|
Methods Summary |
---|
public abstract void | add(int field, int value)Adds the specified amount to a {@code Calendar} field.
| public boolean | after(java.lang.Object calendar)Returns whether the {@code Date} specified by this {@code Calendar} instance is after the {@code Date}
specified by the parameter. The comparison is not dependent on the time
zones of the {@code Calendar}.
if (!(calendar instanceof Calendar)) {
return false;
}
return getTimeInMillis() > ((Calendar) calendar).getTimeInMillis();
| public boolean | before(java.lang.Object calendar)Returns whether the {@code Date} specified by this {@code Calendar} instance is before the
{@code Date} specified by the parameter. The comparison is not dependent on the
time zones of the {@code Calendar}.
if (!(calendar instanceof Calendar)) {
return false;
}
return getTimeInMillis() < ((Calendar) calendar).getTimeInMillis();
| public final void | clear()Clears all of the fields of this {@code Calendar}. All fields are initialized to
zero.
for (int i = 0; i < FIELD_COUNT; i++) {
fields[i] = 0;
isSet[i] = false;
}
areFieldsSet = isTimeSet = false;
| public final void | clear(int field)Clears the specified field to zero and sets the isSet flag to {@code false}.
fields[field] = 0;
isSet[field] = false;
areFieldsSet = isTimeSet = false;
| public java.lang.Object | clone()Returns a new {@code Calendar} with the same properties.
try {
Calendar clone = (Calendar) super.clone();
clone.fields = fields.clone();
clone.isSet = isSet.clone();
clone.zone = (TimeZone) zone.clone();
return clone;
} catch (CloneNotSupportedException e) {
return null;
}
| public int | compareTo(java.util.Calendar anotherCalendar)Compares the times of the two {@code Calendar}, which represent the milliseconds
from the January 1, 1970 00:00:00.000 GMT (Gregorian).
if (null == anotherCalendar) {
throw new NullPointerException();
}
long timeInMillis = getTimeInMillis();
long anotherTimeInMillis = anotherCalendar.getTimeInMillis();
if (timeInMillis > anotherTimeInMillis) {
return 1;
}
if (timeInMillis == anotherTimeInMillis) {
return 0;
}
return -1;
| protected void | complete()Computes the time from the fields if the time has not already been set.
Computes the fields from the time if the fields are not already set.
if (!isTimeSet) {
computeTime();
isTimeSet = true;
}
if (!areFieldsSet) {
computeFields();
areFieldsSet = true;
}
| protected abstract void | computeFields()Computes the {@code Calendar} fields from {@code time}.
| protected abstract void | computeTime()Computes {@code time} from the Calendar fields.
| public boolean | equals(java.lang.Object object)Compares the specified object to this {@code Calendar} and returns whether they are
equal. The object must be an instance of {@code Calendar} and have the same
properties.
if (this == object) {
return true;
}
if (!(object instanceof Calendar)) {
return false;
}
Calendar cal = (Calendar) object;
return getTimeInMillis() == cal.getTimeInMillis()
&& isLenient() == cal.isLenient()
&& getFirstDayOfWeek() == cal.getFirstDayOfWeek()
&& getMinimalDaysInFirstWeek() == cal
.getMinimalDaysInFirstWeek()
&& getTimeZone().equals(cal.getTimeZone());
| public int | get(int field)Gets the value of the specified field after computing the field values by
calling {@code complete()} first.
complete();
return fields[field];
| public int | getActualMaximum(int field)Gets the maximum value of the specified field for the current date.
int value, next;
if (getMaximum(field) == (next = getLeastMaximum(field))) {
return next;
}
complete();
long orgTime = time;
set(field, next);
do {
value = next;
roll(field, true);
next = get(field);
} while (next > value);
time = orgTime;
areFieldsSet = false;
return value;
| public int | getActualMinimum(int field)Gets the minimum value of the specified field for the current date.
int value, next;
if (getMinimum(field) == (next = getGreatestMinimum(field))) {
return next;
}
complete();
long orgTime = time;
set(field, next);
do {
value = next;
roll(field, false);
next = get(field);
} while (next < value);
time = orgTime;
areFieldsSet = false;
return value;
| public static synchronized java.util.Locale[] | getAvailableLocales()Gets the list of installed {@code Locale}s which support {@code Calendar}.
return Locale.getAvailableLocales();
| public int | getFirstDayOfWeek()Gets the first day of the week for this {@code Calendar}.
return firstDayOfWeek;
| public abstract int | getGreatestMinimum(int field)Gets the greatest minimum value of the specified field. This is the
biggest value that {@code getActualMinimum} can return for any possible
time.
| public static synchronized java.util.Calendar | getInstance()Constructs a new instance of the {@code Calendar} subclass appropriate for the
default {@code Locale}.
return new GregorianCalendar();
| public static synchronized java.util.Calendar | getInstance(java.util.Locale locale)Constructs a new instance of the {@code Calendar} subclass appropriate for the
specified {@code Locale}.
return new GregorianCalendar(locale);
| public static synchronized java.util.Calendar | getInstance(java.util.TimeZone timezone)Constructs a new instance of the {@code Calendar} subclass appropriate for the
default {@code Locale}, using the specified {@code TimeZone}.
return new GregorianCalendar(timezone);
| public static synchronized java.util.Calendar | getInstance(java.util.TimeZone timezone, java.util.Locale locale)Constructs a new instance of the {@code Calendar} subclass appropriate for the
specified {@code Locale}.
return new GregorianCalendar(timezone, locale);
| public abstract int | getLeastMaximum(int field)Gets the smallest maximum value of the specified field. This is the
smallest value that {@code getActualMaximum()} can return for any
possible time.
| public abstract int | getMaximum(int field)Gets the greatest maximum value of the specified field. This returns the
biggest value that {@code get} can return for the specified field.
| public int | getMinimalDaysInFirstWeek()Gets the minimal days in the first week of the year.
return minimalDaysInFirstWeek;
| public abstract int | getMinimum(int field)Gets the smallest minimum value of the specified field. this returns the
smallest value thet {@code get} can return for the specified field.
| public final java.util.Date | getTime()Gets the time of this {@code Calendar} as a {@code Date} object.
return new Date(getTimeInMillis());
| public long | getTimeInMillis()Computes the time from the fields if required and returns the time.
if (!isTimeSet) {
computeTime();
isTimeSet = true;
}
return time;
| public java.util.TimeZone | getTimeZone()Gets the timezone of this {@code Calendar}.
return zone;
| public int | hashCode()Returns an integer hash code for the receiver. Objects which are equal
return the same value for this method.
return (isLenient() ? 1237 : 1231) + getFirstDayOfWeek()
+ getMinimalDaysInFirstWeek() + getTimeZone().hashCode();
| protected final int | internalGet(int field)Gets the value of the specified field without recomputing.
return fields[field];
| public boolean | isLenient()Returns if this {@code Calendar} accepts field values which are outside the valid
range for the field.
return lenient;
| public final boolean | isSet(int field)Returns whether the specified field is set.
return isSet[field];
| private void | readObject(java.io.ObjectInputStream stream)
ObjectInputStream.GetField readFields = stream.readFields();
areFieldsSet = readFields.get("areFieldsSet", false); //$NON-NLS-1$
this.fields = (int[]) readFields.get("fields", null); //$NON-NLS-1$
firstDayOfWeek = readFields.get("firstDayOfWeek", Calendar.SUNDAY); //$NON-NLS-1$
isSet = (boolean[]) readFields.get("isSet", null); //$NON-NLS-1$
isTimeSet = readFields.get("isTimeSet", false); //$NON-NLS-1$
lenient = readFields.get("lenient", true); //$NON-NLS-1$
minimalDaysInFirstWeek = readFields.get("minimalDaysInFirstWeek", 1); //$NON-NLS-1$
time = readFields.get("time", 0L); //$NON-NLS-1$
zone = (TimeZone) readFields.get("zone", null); //$NON-NLS-1$
| public void | roll(int field, int value)Adds the specified amount to the specified field and wraps the value of
the field when it goes beyond the maximum or minimum value for the
current date. Other fields will be adjusted as required to maintain a
consistent date.
boolean increment = value >= 0;
int count = increment ? value : -value;
for (int i = 0; i < count; i++) {
roll(field, increment);
}
| public abstract void | roll(int field, boolean increment)Increment or decrement the specified field and wrap the value of the
field when it goes beyond the maximum or minimum value for the current
date. Other fields will be adjusted as required to maintain a consistent
date.
| public void | set(int field, int value)Sets a field to the specified value.
fields[field] = value;
isSet[field] = true;
areFieldsSet = isTimeSet = false;
if (field > MONTH && field < AM_PM) {
lastDateFieldSet = field;
}
if (field == HOUR || field == HOUR_OF_DAY) {
lastTimeFieldSet = field;
}
if (field == AM_PM) {
lastTimeFieldSet = HOUR;
}
| public final void | set(int year, int month, int day)Sets the year, month and day of the month fields. Other fields are not
changed.
set(YEAR, year);
set(MONTH, month);
set(DATE, day);
| public final void | set(int year, int month, int day, int hourOfDay, int minute)Sets the year, month, day of the month, hour of day and minute fields.
Other fields are not changed.
set(year, month, day);
set(HOUR_OF_DAY, hourOfDay);
set(MINUTE, minute);
| public final void | set(int year, int month, int day, int hourOfDay, int minute, int second)Sets the year, month, day of the month, hour of day, minute and second
fields. Other fields are not changed.
set(year, month, day, hourOfDay, minute);
set(SECOND, second);
| public void | setFirstDayOfWeek(int value)Sets the first day of the week for this {@code Calendar}.
firstDayOfWeek = value;
| public void | setLenient(boolean value)Sets this {@code Calendar} to accept field values which are outside the valid
range for the field.
lenient = value;
| public void | setMinimalDaysInFirstWeek(int value)Sets the minimal days in the first week of the year.
minimalDaysInFirstWeek = value;
| public final void | setTime(java.util.Date date)Sets the time of this {@code Calendar}.
setTimeInMillis(date.getTime());
| public void | setTimeInMillis(long milliseconds)Sets the time of this {@code Calendar}.
time = milliseconds;
isTimeSet = true;
areFieldsSet = false;
complete();
| public void | setTimeZone(java.util.TimeZone timezone)Sets the {@code TimeZone} used by this Calendar.
zone = timezone;
| public java.lang.String | toString()Returns the string representation of this {@code Calendar}.
StringBuffer result = new StringBuffer(getClass().getName() + "[time=" //$NON-NLS-1$
+ (isTimeSet ? String.valueOf(time) : "?") + ",areFieldsSet=" //$NON-NLS-1$//$NON-NLS-2$
+ areFieldsSet +
// ",areAllFieldsSet=" + areAllFieldsSet +
",lenient=" + lenient + ",zone=" + zone + ",firstDayOfWeek=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ firstDayOfWeek + ",minimalDaysInFirstWeek=" //$NON-NLS-1$
+ minimalDaysInFirstWeek);
for (int i = 0; i < FIELD_COUNT; i++) {
result.append(',");
result.append(fieldNames[i]);
result.append('=");
if (isSet[i]) {
result.append(fields[i]);
} else {
result.append('?");
}
}
result.append(']");
return result.toString();
| private void | writeObject(java.io.ObjectOutputStream stream) //$NON-NLS-1$
complete();
ObjectOutputStream.PutField putFields = stream.putFields();
putFields.put("areFieldsSet", areFieldsSet); //$NON-NLS-1$
putFields.put("fields", this.fields); //$NON-NLS-1$
putFields.put("firstDayOfWeek", firstDayOfWeek); //$NON-NLS-1$
putFields.put("isSet", isSet); //$NON-NLS-1$
putFields.put("isTimeSet", isTimeSet); //$NON-NLS-1$
putFields.put("lenient", lenient); //$NON-NLS-1$
putFields.put("minimalDaysInFirstWeek", minimalDaysInFirstWeek); //$NON-NLS-1$
putFields.put("nextStamp", 2 /* MINIMUM_USER_STAMP */); //$NON-NLS-1$
putFields.put("serialVersionOnStream", 1); //$NON-NLS-1$
putFields.put("time", time); //$NON-NLS-1$
putFields.put("zone", zone); //$NON-NLS-1$
stream.writeFields();
|
|