FileDocCategorySizeDatePackage
Calendar.javaAPI DocAndroid 1.5 API52609Wed May 06 22:41:04 BST 2009java.util

Calendar

public 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:

  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 form a sequence of three consecutive minutes in time.
  2. 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.

see
Date
see
GregorianCalendar
see
TimeZone
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
protected boolean
areFieldsSet
Set 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[]
fields
An integer array of calendar fields. The length is {@code FIELD_COUNT}.
protected boolean[]
isSet
A boolean array. Each element indicates if the corresponding field has been set. The length is {@code FIELD_COUNT}.
protected boolean
isTimeSet
Set 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
time
The 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
JANUARY
Value of the {@code MONTH} field indicating the first month of the year.
public static final int
FEBRUARY
Value of the {@code MONTH} field indicating the second month of the year.
public static final int
MARCH
Value of the {@code MONTH} field indicating the third month of the year.
public static final int
APRIL
Value of the {@code MONTH} field indicating the fourth month of the year.
public static final int
MAY
Value of the {@code MONTH} field indicating the fifth month of the year.
public static final int
JUNE
Value of the {@code MONTH} field indicating the sixth month of the year.
public static final int
JULY
Value of the {@code MONTH} field indicating the seventh month of the year.
public static final int
AUGUST
Value of the {@code MONTH} field indicating the eighth month of the year.
public static final int
SEPTEMBER
Value of the {@code MONTH} field indicating the ninth month of the year.
public static final int
OCTOBER
Value of the {@code MONTH} field indicating the tenth month of the year.
public static final int
NOVEMBER
Value of the {@code MONTH} field indicating the eleventh month of the year.
public static final int
DECEMBER
Value of the {@code MONTH} field indicating the twelfth month of the year.
public static final int
UNDECIMBER
Value 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
SUNDAY
Value of the {@code DAY_OF_WEEK} field indicating Sunday.
public static final int
MONDAY
Value of the {@code DAY_OF_WEEK} field indicating Monday.
public static final int
TUESDAY
Value of the {@code DAY_OF_WEEK} field indicating Tuesday.
public static final int
WEDNESDAY
Value of the {@code DAY_OF_WEEK} field indicating Wednesday.
public static final int
THURSDAY
Value of the {@code DAY_OF_WEEK} field indicating Thursday.
public static final int
FRIDAY
Value of the {@code DAY_OF_WEEK} field indicating Friday.
public static final int
SATURDAY
Value of the {@code DAY_OF_WEEK} field indicating Saturday.
public static final int
ERA
Field 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
YEAR
Field number for {@code get} and {@code set} indicating the year. This is a calendar-specific value; see subclass documentation.
public static final int
MONTH
Field 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_YEAR
Field 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_MONTH
Field 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
DATE
Field 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_MONTH
Field 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_YEAR
Field 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_WEEK
Field 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_MONTH
Field 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_PM
Field 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
HOUR
Field 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_DAY
Field 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
MINUTE
Field 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
SECOND
Field 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
MILLISECOND
Field 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_OFFSET
Field number for {@code get} and {@code set} indicating the raw offset from GMT in milliseconds.
public static final int
DST_OFFSET
Field number for {@code get} and {@code set} indicating the daylight savings offset in milliseconds.
public static final int
FIELD_COUNT
This is the total number of fields in this calendar.
public static final int
AM
Value of the {@code AM_PM} field indicating the period of the day from midnight to just before noon.
public static final int
PM
Value 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}.

since
Android 1.0

 //$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}.

param
timezone the timezone.
param
locale the locale.
since
Android 1.0

        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 voidadd(int field, int value)
Adds the specified amount to a {@code Calendar} field.

param
field the {@code Calendar} field to modify.
param
value the amount to add to the field.
since
Android 1.0

public booleanafter(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}.

param
calendar the {@code Calendar} instance to compare.
return
{@code true} when this Calendar is after calendar, {@code false} otherwise.
since
Android 1.0

        if (!(calendar instanceof Calendar)) {
            return false;
        }
        return getTimeInMillis() > ((Calendar) calendar).getTimeInMillis();
    
public booleanbefore(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}.

param
calendar the {@code Calendar} instance to compare.
return
{@code true} when this Calendar is before calendar, {@code false} otherwise.
since
Android 1.0

        if (!(calendar instanceof Calendar)) {
            return false;
        }
        return getTimeInMillis() < ((Calendar) calendar).getTimeInMillis();
    
public final voidclear()
Clears all of the fields of this {@code Calendar}. All fields are initialized to zero.

since
Android 1.0

        for (int i = 0; i < FIELD_COUNT; i++) {
            fields[i] = 0;
            isSet[i] = false;
        }
        areFieldsSet = isTimeSet = false;
    
public final voidclear(int field)
Clears the specified field to zero and sets the isSet flag to {@code false}.

param
field the field to clear.
since
Android 1.0

        fields[field] = 0;
        isSet[field] = false;
        areFieldsSet = isTimeSet = false;
    
public java.lang.Objectclone()
Returns a new {@code Calendar} with the same properties.

return
a shallow copy of this {@code Calendar}.
see
java.lang.Cloneable
since
Android 1.0

        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 intcompareTo(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).

param
anotherCalendar another calendar that this one is compared with.
return
0 if the times of the two {@code Calendar}s are equal, -1 if the time of this {@code Calendar} is before the other one, 1 if the time of this {@code Calendar} is after the other one.
throws
NullPointerException if the argument is null.
throws
IllegalArgumentException if the argument does not include a valid time value.
since
Android 1.0

        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 voidcomplete()
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.

exception
IllegalArgumentException when the time is not set and the time cannot be computed from the current field values.
since
Android 1.0

        if (!isTimeSet) {
            computeTime();
            isTimeSet = true;
        }
        if (!areFieldsSet) {
            computeFields();
            areFieldsSet = true;
        }
    
protected abstract voidcomputeFields()
Computes the {@code Calendar} fields from {@code time}.

since
Android 1.0

protected abstract voidcomputeTime()
Computes {@code time} from the Calendar fields.

exception
IllegalArgumentException when the time cannot be computed from the current field values.
since
Android 1.0

public booleanequals(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.

param
object the object to compare with this object.
return
{@code true} if the specified object is equal to this {@code Calendar}, {@code false} otherwise.
since
Android 1.0

        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 intget(int field)
Gets the value of the specified field after computing the field values by calling {@code complete()} first.

param
field the field to get.
return
the value of the specified field.
exception
IllegalArgumentException when the fields are not set, the time is not set, and the time cannot be computed from the current field values.
exception
ArrayIndexOutOfBoundsException if the field is not inside the range of possible fields. The range is starting at 0 up to {@code FIELD_COUNT}.
since
Android 1.0

        complete();
        return fields[field];
    
public intgetActualMaximum(int field)
Gets the maximum value of the specified field for the current date.

param
field the field.
return
the maximum value of the specified field.
since
Android 1.0

        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 intgetActualMinimum(int field)
Gets the minimum value of the specified field for the current date.

param
field the field.
return
the minimum value of the specified field.
since
Android 1.0

        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
an array of {@code Locale}.
since
Android 1.0

        return Locale.getAvailableLocales();
    
public intgetFirstDayOfWeek()
Gets the first day of the week for this {@code Calendar}.

return
the first day of the week.
since
Android 1.0

        return firstDayOfWeek;
    
public abstract intgetGreatestMinimum(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.

param
field the field.
return
the greatest minimum value of the specified field.
since
Android 1.0

public static synchronized java.util.CalendargetInstance()
Constructs a new instance of the {@code Calendar} subclass appropriate for the default {@code Locale}.

return
a {@code Calendar} subclass instance set to the current date and time in the default {@code Timezone}.
since
Android 1.0

        return new GregorianCalendar();
    
public static synchronized java.util.CalendargetInstance(java.util.Locale locale)
Constructs a new instance of the {@code Calendar} subclass appropriate for the specified {@code Locale}.

param
locale the locale to use.
return
a {@code Calendar} subclass instance set to the current date and time.
since
Android 1.0

        return new GregorianCalendar(locale);
    
public static synchronized java.util.CalendargetInstance(java.util.TimeZone timezone)
Constructs a new instance of the {@code Calendar} subclass appropriate for the default {@code Locale}, using the specified {@code TimeZone}.

param
timezone the {@code TimeZone} to use.
return
a {@code Calendar} subclass instance set to the current date and time in the specified timezone.
since
Android 1.0

        return new GregorianCalendar(timezone);
    
public static synchronized java.util.CalendargetInstance(java.util.TimeZone timezone, java.util.Locale locale)
Constructs a new instance of the {@code Calendar} subclass appropriate for the specified {@code Locale}.

param
timezone the {@code TimeZone} to use.
param
locale the {@code Locale} to use.
return
a {@code Calendar} subclass instance set to the current date and time in the specified timezone.
since
Android 1.0

        return new GregorianCalendar(timezone, locale);
    
public abstract intgetLeastMaximum(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.

param
field the field number.
return
the smallest maximum value of the specified field.
since
Android 1.0

public abstract intgetMaximum(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.

param
field the field.
return
the greatest maximum value of the specified field.
since
Android 1.0

public intgetMinimalDaysInFirstWeek()
Gets the minimal days in the first week of the year.

return
the minimal days in the first week of the year.
since
Android 1.0

        return minimalDaysInFirstWeek;
    
public abstract intgetMinimum(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.

param
field the field number.
return
the smallest minimum value of the specified field.
since
Android 1.0

public final java.util.DategetTime()
Gets the time of this {@code Calendar} as a {@code Date} object.

return
a new {@code Date} initialized to the time of this {@code Calendar}.
exception
IllegalArgumentException when the time is not set and the time cannot be computed from the current field values.
since
Android 1.0

        return new Date(getTimeInMillis());
    
public longgetTimeInMillis()
Computes the time from the fields if required and returns the time.

return
the time of this {@code Calendar}.
exception
IllegalArgumentException when the time is not set and the time cannot be computed from the current field values.
since
Android 1.0

        if (!isTimeSet) {
            computeTime();
            isTimeSet = true;
        }
        return time;
    
public java.util.TimeZonegetTimeZone()
Gets the timezone of this {@code Calendar}.

return
the {@code TimeZone} used by this {@code Calendar}.
since
Android 1.0

        return zone;
    
public inthashCode()
Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.

return
the receiver's hash.
see
#equals
since
Android 1.0

        return (isLenient() ? 1237 : 1231) + getFirstDayOfWeek()
                + getMinimalDaysInFirstWeek() + getTimeZone().hashCode();
    
protected final intinternalGet(int field)
Gets the value of the specified field without recomputing.

param
field the field.
return
the value of the specified field.
since
Android 1.0

        return fields[field];
    
public booleanisLenient()
Returns if this {@code Calendar} accepts field values which are outside the valid range for the field.

return
{@code true} if this {@code Calendar} is lenient, {@code false} otherwise.
since
Android 1.0

        return lenient;
    
public final booleanisSet(int field)
Returns whether the specified field is set.

param
field a {@code Calendar} field number.
return
{@code true} if the specified field is set, {@code false} otherwise.
since
Android 1.0

        return isSet[field];
    
private voidreadObject(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 voidroll(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.

param
field the field to roll.
param
value the amount to add.
since
Android 1.0

        boolean increment = value >= 0;
        int count = increment ? value : -value;
        for (int i = 0; i < count; i++) {
            roll(field, increment);
        }
    
public abstract voidroll(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.

param
field the number indicating the field to roll.
param
increment {@code true} to increment the field, {@code false} to decrement.
since
Android 1.0

public voidset(int field, int value)
Sets a field to the specified value.

param
field the code indicating the {@code Calendar} field to modify.
param
value the value.
since
Android 1.0

        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 voidset(int year, int month, int day)
Sets the year, month and day of the month fields. Other fields are not changed.

param
year the year.
param
month the month.
param
day the day of the month.
since
Android 1.0

        set(YEAR, year);
        set(MONTH, month);
        set(DATE, day);
    
public final voidset(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.

param
year the year.
param
month the month.
param
day the day of the month.
param
hourOfDay the hour of day.
param
minute the minute.
since
Android 1.0

        set(year, month, day);
        set(HOUR_OF_DAY, hourOfDay);
        set(MINUTE, minute);
    
public final voidset(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.

param
year the year.
param
month the month.
param
day the day of the month.
param
hourOfDay the hour of day.
param
minute the minute.
param
second the second.
since
Android 1.0

        set(year, month, day, hourOfDay, minute);
        set(SECOND, second);
    
public voidsetFirstDayOfWeek(int value)
Sets the first day of the week for this {@code Calendar}.

param
value a {@code Calendar} day of the week.
since
Android 1.0

        firstDayOfWeek = value;
    
public voidsetLenient(boolean value)
Sets this {@code Calendar} to accept field values which are outside the valid range for the field.

param
value a boolean value.
since
Android 1.0

        lenient = value;
    
public voidsetMinimalDaysInFirstWeek(int value)
Sets the minimal days in the first week of the year.

param
value the minimal days in the first week of the year.
since
Android 1.0

        minimalDaysInFirstWeek = value;
    
public final voidsetTime(java.util.Date date)
Sets the time of this {@code Calendar}.

param
date a {@code Date} object.
since
Android 1.0

        setTimeInMillis(date.getTime());
    
public voidsetTimeInMillis(long milliseconds)
Sets the time of this {@code Calendar}.

param
milliseconds the time as the number of milliseconds since Jan. 1, 1970.
since
Android 1.0

        time = milliseconds;
        isTimeSet = true;
        areFieldsSet = false;
        complete();
    
public voidsetTimeZone(java.util.TimeZone timezone)
Sets the {@code TimeZone} used by this Calendar.

param
timezone a {@code TimeZone}.
since
Android 1.0

        zone = timezone;
    
public java.lang.StringtoString()
Returns the string representation of this {@code Calendar}.

return
the string representation of this {@code Calendar}.
since
Android 1.0

        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 voidwriteObject(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();