DthingApi
|
Public Member Functions | |
abstract void | add (int field, int value) |
boolean | after (Object calendar) |
boolean | before (Object calendar) |
final void | clear () |
final void | clear (int field) |
Object | clone () |
boolean | equals (Object object) |
int | get (int field) |
int | getActualMaximum (int field) |
int | getActualMinimum (int field) |
int | getFirstDayOfWeek () |
abstract int | getGreatestMinimum (int field) |
abstract int | getLeastMaximum (int field) |
abstract int | getMaximum (int field) |
int | getMinimalDaysInFirstWeek () |
abstract int | getMinimum (int field) |
final Date | getTime () |
long | getTimeInMillis () |
TimeZone | getTimeZone () |
int | hashCode () |
boolean | isLenient () |
final boolean | isSet (int field) |
void | roll (int field, int value) |
abstract void | roll (int field, boolean increment) |
void | set (int field, int value) |
final void | set (int year, int month, int day) |
final void | set (int year, int month, int day, int hourOfDay, int minute) |
final void | set (int year, int month, int day, int hourOfDay, int minute, int second) |
void | setFirstDayOfWeek (int value) |
void | setLenient (boolean value) |
void | setMinimalDaysInFirstWeek (int value) |
final void | setTime (Date date) |
void | setTimeInMillis (long milliseconds) |
void | setTimeZone (TimeZone timezone) |
String | toString () |
Static Public Member Functions | |
static synchronized Locale [] | getAvailableLocales () |
static synchronized Calendar | getInstance () |
static synchronized Calendar | getInstance (Locale locale) |
static synchronized Calendar | getInstance (TimeZone timezone) |
static synchronized Calendar | getInstance (TimeZone timezone, Locale locale) |
Static Public Attributes | |
static final int | JANUARY = 0 |
static final int | FEBRUARY = 1 |
static final int | MARCH = 2 |
static final int | APRIL = 3 |
static final int | MAY = 4 |
static final int | JUNE = 5 |
static final int | JULY = 6 |
static final int | AUGUST = 7 |
static final int | SEPTEMBER = 8 |
static final int | OCTOBER = 9 |
static final int | NOVEMBER = 10 |
static final int | DECEMBER = 11 |
static final int | UNDECIMBER = 12 |
static final int | SUNDAY = 1 |
static final int | MONDAY = 2 |
static final int | TUESDAY = 3 |
static final int | WEDNESDAY = 4 |
static final int | THURSDAY = 5 |
static final int | FRIDAY = 6 |
static final int | SATURDAY = 7 |
static final int | ERA = 0 |
static final int | YEAR = 1 |
static final int | MONTH = 2 |
static final int | WEEK_OF_YEAR = 3 |
static final int | WEEK_OF_MONTH = 4 |
static final int | DATE = 5 |
static final int | DAY_OF_MONTH = 5 |
static final int | DAY_OF_YEAR = 6 |
static final int | DAY_OF_WEEK = 7 |
static final int | DAY_OF_WEEK_IN_MONTH = 8 |
static final int | AM_PM = 9 |
static final int | HOUR = 10 |
static final int | HOUR_OF_DAY = 11 |
static final int | MINUTE = 12 |
static final int | SECOND = 13 |
static final int | MILLISECOND = 14 |
static final int | ZONE_OFFSET = 15 |
static final int | DST_OFFSET = 16 |
static final int | FIELD_COUNT = 17 |
static final int | AM = 0 |
static final int | PM = 1 |
static final int | ALL_STYLES = 0 |
static final int | SHORT = 1 |
static final int | LONG = 2 |
Protected Member Functions | |
Calendar () | |
Calendar (TimeZone timezone, Locale locale) | |
void | complete () |
abstract void | computeFields () |
abstract void | computeTime () |
final int | internalGet (int field) |
Protected Attributes | |
boolean | areFieldsSet |
int [] | fields |
boolean [] | isSet |
boolean | isTimeSet |
long | time |
is an abstract base class for converting between a
object and a set of integer fields such as
,
,
,
, and so on. (A
object represents a specific instant in time with millisecond precision. See Date for information about the
class.)
Subclasses of
interpret a
according to the rules of a specific calendar system.
Like other locale-sensitive classes,
provides a class method,
, for getting a default instance of this class for general use.
's
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
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).
defines the range of values returned by certain fields, as well as their meaning. For example, the first month of the year has value
==
for all calendars. Other values are defined by the concrete subclass, such as
and
. See individual field documentation and subclass documentation for details.
When a
is lenient, it accepts a wider range of field values than it produces. For example, a lenient
interprets
==
,
== 32 as February 1. A non-lenient
throws an exception when given out-of-range field settings. When calendars recompute field values for return by
, they normalize them. For example, a
always produces
values between 1 and the length of the month.
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
is constructed. They may also be specified explicitly through the API.
When setting or getting the
or
fields,
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
and containing at least
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
may be different. For example, a specific
subclass may designate the week before week 1 of a year as week n of the previous year.
When computing a
from time fields, two special circumstances may arise: there may be insufficient information to compute the
(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.
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 java.text.DateFormat to format dates.
Field manipulation methods
fields can be changed using three methods:
,
, and
.
changes field
to
. In addition, it sets an internal member variable to indicate that field
has been changed. Although field
is changed immediately, the calendar's milliseconds is not recomputed until the next call to
,
, or
is made. Thus, multiple calls to
do not trigger multiple, unnecessary computations. As a result of changing a field using
, other fields may also change, depending on the field, the field value, and the calendar system. In addition,
will not necessarily return
after the fields have been recomputed. The specifics are determined by the concrete calendar class.
Example: Consider a
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
is then called. However, a call to
before the call to
sets the calendar to September 30, 1999, since no recomputation occurs after
itself.
adds
to field
. This is equivalent to calling set(f, get(f) + delta)
with two adjustments:
Add rule 1. The value of field
fafter the call minus the value of field
fbefore 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
fis 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.
is a smaller field than
. 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
,
forces an immediate recomputation of the calendar's milliseconds and all fields.
Example: Consider a
originally set to August 31, 1999. Calling
sets the calendar to September 30, 2000. Add rule 1 sets the
field to September, since adding 13 months to August gives September of the next year. Since
cannot be 31 in September in a
, add rule 2 sets the
to 30, the closest possible value. Although it is a smaller field,
is not adjusted by rule 2, since it is expected to change when the month changes in a
.
adds
to field
without changing larger fields. This is equivalent to calling
with the following adjustment:
Roll rule. Larger fields are unchanged after the call. A larger field represents a larger unit of time.
is a larger field than
.
Example: Consider a
originally set to August 31, 1999. Calling roll(Calendar.MONTH, 8)
sets the calendar to April 30, 1999. Add rule 1 sets the
field to April. Using a
, the
cannot be 31 in the month April. Add rule 2 sets it to the closest possible value, 30. Finally, the roll rule maintains the
field value of 1999.
Example: Consider a
originally set to Sunday June 6, 1999. Calling
sets the calendar to Tuesday June 1, 1999, whereas calling
sets the calendar to Sunday May 30, 1999. This is because the roll rule imposes an additional constraint: The
must not change when the
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
, an invariant when changing the
, 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
and
, consider a user interface component with increment and decrement buttons for the month, day, and year, and an underlying
. If the interface reads January 31, 1999 and the user presses the month increment button, what should it read? If the underlying implementation uses
, 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
or
, depending on whether larger fields should be affected, the user interface can behave as most users will intuitively expect.
Note: You should always use
and
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.
|
inlineprotected |
Constructs a
instance using the specified
and
.
timezone | the timezone. |
locale | the locale. |
|
abstract |
Adds the specified amount to a
field.
field | the field to modify. |
value | the amount to add to the field. |
IllegalArgumentException | if field |
|
inline |
Returns whether the
specified by this
instance is after the
specified by the parameter. The comparison is not dependent on the time zones of the
.
calendar | the instance to compare. |
IllegalArgumentException | if the time is not set and the time cannot be computed from the current field values. |
|
inline |
Returns whether the
specified by this
instance is before the
specified by the parameter. The comparison is not dependent on the time zones of the
.
calendar | the instance to compare. |
IllegalArgumentException | if the time is not set and the time cannot be computed from the current field values. |
|
inline |
|
inline |
Clears the specified field to zero and sets the isSet flag to
.
field | the field to clear. |
|
inline |
|
inlineprotected |
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.
IllegalArgumentException | if the time is not set and the time cannot be computed from the current field values. |
|
abstractprotected |
|
abstractprotected |
|
inline |
|
inline |
Gets the value of the specified field after computing the field values by calling
first.
field | the field to get. |
IllegalArgumentException | if the fields are not set, the time is not set, and the time cannot be computed from the current field values. |
ArrayIndexOutOfBoundsException | if the field is not inside the range of possible fields. The range is starting at 0 up to . |
|
inline |
Gets the maximum value of the specified field for the current date.
field | the field. |
|
inline |
Gets the minimum value of the specified field for the current date.
field | the field. |
|
inlinestatic |
Returns an array of locales for which custom
instances are available.
Note that Android does not support user-supplied locale service providers.
|
inline |
|
abstract |
Gets the greatest minimum value of the specified field. This is the biggest value that
can return for any possible time.
field | the field. |
|
inlinestatic |
|
abstract |
Gets the smallest maximum value of the specified field. This is the smallest value that
can return for any possible time.
field | the field number. |
|
abstract |
Gets the greatest maximum value of the specified field. This returns the biggest value that
can return for the specified field.
field | the field. |
|
inline |
Gets the minimal days in the first week of the year.
|
abstract |
Gets the smallest minimum value of the specified field. this returns the smallest value thet
can return for the specified field.
field | the field number. |
|
inline |
|
inline |
Computes the time from the fields if required and returns the time.
IllegalArgumentException | if the time is not set and the time cannot be computed from the current field values. |
|
inline |
|
inline |
Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.
|
inlineprotected |
Gets the value of the specified field without recomputing.
field | the field. |
|
inline |
|
inline |
Returns whether the specified field is set. Note that the interpretation of "is set" is somewhat technical. In particular, it does not mean that the field's value is up to date. If you want to know whether a field contains an up-to-date value, you must also check
, making this method somewhat useless unless you're a subclass, in which case you can access the
array directly.
A field remains "set" from the first time its value is computed until it's cleared by one of the
methods. Thus "set" does not mean "valid". You probably want to call
– which will update fields as necessary – rather than try to make use of this method.
field | a field number. |
|
inline |
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.
field | the field to roll. |
value | the amount to add. |
|
abstract |
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.
field | the number indicating the field to roll. |
increment | true false |
|
inline |
Sets a field to the specified value.
field | the code indicating the field to modify. |
value | the value. |
|
inline |
Sets the year, month and day of the month fields. Other fields are not changed.
year | the year. |
month | the month. |
day | the day of the month. |
|
inline |
Sets the year, month, day of the month, hour of day and minute fields. Other fields are not changed.
year | the year. |
month | the month. |
day | the day of the month. |
hourOfDay | the hour of day. |
minute | the minute. |
|
inline |
Sets the year, month, day of the month, hour of day, minute and second fields. Other fields are not changed.
year | the year. |
month | the month. |
day | the day of the month. |
hourOfDay | the hour of day. |
minute | the minute. |
second | the second. |
|
inline |
|
inline |
Sets this
to accept field values which are outside the valid range for the field.
value | a boolean value. |
|
inline |
Sets the minimal days in the first week of the year.
value | the minimal days in the first week of the year. |
|
inline |
|
inline |
Sets the time of this
.
milliseconds | the time as the number of milliseconds since Jan. 1, 1970. |
|
inline |
|
inline |
|
static |
|
static |
|
static |
|
static |
|
protected |
|
static |
|
static |
Field number for
and
indicating the day of the month. This is a synonym for
. The first day of the month has value 1.
|
static |
|
static |
|
static |
Field number for
and
indicating the ordinal number of the day of the week within the current month. Together with the
field, this uniquely specifies a day within a month. Unlike
and
, this field's value does not depend on
or
.
through
always correspond to DAY_OF_WEEK_IN_MONTH 1
;
through
correspond to
, and so on.
indicates the week before
. Negative values count back from the end of the month, so the last Sunday of a month is specified as
. 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,
will overlap
and the end of
.
|
static |
Field number for
and
indicating the day number within the current year. The first day of the year has value 1.
|
static |
|
static |
Field number for
and
indicating the daylight savings offset in milliseconds.
|
static |
Field number for
and
indicating the era, e.g., AD or BC in the Julian calendar. This is a calendar-specific value; see subclass documentation.
|
static |
|
static |
This is the total number of fields in this calendar.
|
protected |
Contains broken-down field values for the current value of
if
is true, or stale data corresponding to some previous value otherwise. Accessing the fields via
will ensure the fields are up-to-date. The array length is always
.
|
static |
|
static |
Field number for
and
indicating the hour of the morning or afternoon.
is used for the 12-hour clock. E.g., at 10:04:15.250 PM the
is 10.
|
static |
Field number for
and
indicating the hour of the day.
is used for the 24-hour clock. E.g., at 10:04:15.250 PM the
is 22.
|
protected |
Whether the corresponding element in
has been set. Initially, these are all false. The first time the fields are computed, these are set to true and remain set even if the data becomes stale: you must check
if you want to know whether the value is up-to-date. Note that
is not a safe alternative to accessing this array directly, and will likewise return stale data! The array length is always
.
|
protected |
|
static |
|
static |
|
static |
|
static |
Requests long names (such as "January") from getDisplayName or getDisplayNames.
|
static |
|
static |
|
static |
Field number for
and
indicating the millisecond within the second. E.g., at 10:04:15.250 PM the
is 250.
|
static |
Field number for
and
indicating the minute within the hour. E.g., at 10:04:15.250 PM the
is 4.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Field number for
and
indicating the second within the minute. E.g., at 10:04:15.250 PM the
is 15.
|
static |
|
static |
Requests short names (such as "Jan") from getDisplayName or getDisplayNames.
|
static |
|
static |
|
protected |
A time in milliseconds since January 1, 1970. See
. Accessing the time via
will always return the correct value.
|
static |
|
static |
Value of the
field indicating the thirteenth month of the year. Although
does not use this value, lunar calendars do.
|
static |
|
static |
Field number for
and
indicating the week number within the current month. The first week of the month, as defined by
and
, has value 1. Subclasses define the value of
for days before the first week of the month.
|
static |
Field number for
and
indicating the week number within the current year. The first week of the year, as defined by
and
, has value 1. Subclasses define the value of
for days before the first week of the year.
|
static |
Field number for
and
indicating the year. This is a calendar-specific value; see subclass documentation.
|
static |
Field number for
and
indicating the raw offset from GMT in milliseconds.