java.util
public abstract class Calendar extends Object implements Serializable, Cloneable, Comparable<Calendar>
Date
objects and a set of
integer fields which represent YEAR
,
MONTH
, DAY
, etc. The Date
object represents a time in milliseconds since the Epoch. getInstance
. You can even provide
a locale or a timezone. getInstance
returns currently
a GregorianCalendar
for the current date. Date
-Object, you can create
a new Calendar with getInstance()
,
clear()
all fields, set(int,int)
the
fields you need and convert it with getTime()
. Date
-object to the Calendar
representation, create a new Calendar, assign the
Date
-Object with setTime()
, and read the
fields with get(int)
. month + day_of_month month + week_of_month + day_of_week month + day_of_week_of_month + day_of_week day_of_year day_of_week + week_of_yearThe hour_of_day-field takes precedence over the ampm and hour_of_ampm fields.
java.text.DateFormat
class. roll
ing fields (that means increase/decrease a
specific field by one, propagating overflows), or
add
ing/substracting a fixed amount to a field.
See Also: Date GregorianCalendar TimeZone DateFormat
Field Summary | |
---|---|
static int | ALL_STYLES
A style specifier for {@link #getDisplayNames(int,int,Locale)}
stating that names should be returned in both long and short variants.
|
static int | AM
Useful constant for 12-hour clock. |
static int | AM_PM
Constant representing the part of the day for 12-hour clock. |
static int | APRIL
Constant representing April. |
static int | AUGUST
Constant representing August. |
protected boolean | areFieldsSet
Tells if the fields have a valid value. |
static int | DATE
Constant representing the day time field, synonym for DAY_OF_MONTH. |
static int | DAY_OF_MONTH
Constant representing the day time field. |
static int | DAY_OF_WEEK
Constant representing the day of week time field. |
static int | DAY_OF_WEEK_IN_MONTH
Constant representing the day-of-week-in-month field. |
static int | DAY_OF_YEAR
Constant representing the day of year time field. |
static int | DECEMBER
Constant representing December. |
static int | DST_OFFSET
Constant representing the daylight saving time offset in
milliseconds. |
static int | ERA
Constant representing the era time field. |
protected int[] | fields
The time fields. |
static int | FEBRUARY
Constant representing February. |
static int | FIELD_COUNT
Number of time fields. |
static int | FRIDAY
Constant representing Friday. |
static int | HOUR
Constant representing the hour time field for 12-hour clock. |
static int | HOUR_OF_DAY
Constant representing the hour of day time field for 24-hour clock. |
protected boolean[] | isSet
The flags which tell if the fields above have a value. |
protected boolean | isTimeSet
Tells if the above field has a valid value. |
static int | JANUARY
Constant representing January. |
static int | JULY
Constant representing July. |
static int | JUNE
Constant representing June. |
static int | LONG
A style specifier for {@link #getDisplayName(int,int,Locale)}
and {@link #getDisplayNames(int,int,Locale)} stating that names
should be returned in their long variant if applicable.
|
static int | MARCH
Constant representing March. |
static int | MAY
Constant representing May. |
static int | MILLISECOND
Constant representing the millisecond time field. |
static int | MINUTE
Constant representing the minute of hour time field. |
static int | MONDAY
Constant representing Monday. |
static int | MONTH
Constant representing the month time field. |
static int | NOVEMBER
Constant representing November. |
static int | OCTOBER
Constant representing October. |
static int | PM
Useful constant for 12-hour clock. |
static int | SATURDAY
Constant representing Saturday. |
static int | SECOND
Constant representing the second time field. |
static int | SEPTEMBER
Constant representing September. |
static int | SHORT
A style specifier for {@link #getDisplayName(int,int,Locale)}
and {@link #getDisplayNames(int,int,Locale)} stating that names
should be returned in their short variant if applicable.
|
static int | SUNDAY
Constant representing Sunday. |
protected long | time
The time in milliseconds since the epoch. |
static int | THURSDAY
Constant representing Thursday. |
static int | TUESDAY
Constant representing Tuesday. |
static int | UNDECIMBER
Constant representing Undecimber. |
static int | WEDNESDAY
Constant representing Wednesday. |
static int | WEEK_OF_MONTH
Constant representing the week of the month time field. |
static int | WEEK_OF_YEAR
Constant representing the week of the year field. |
static int | YEAR
Constant representing the year time field. |
static int | ZONE_OFFSET
Constant representing the time zone offset time field for the
time given in the other fields. |
Constructor Summary | |
---|---|
protected | Calendar()
Constructs a new Calendar with the default time zone and the default
locale. |
protected | Calendar(TimeZone zone, Locale locale)
Constructs a new Calendar with the given time zone and the given
locale. |
Method Summary | |
---|---|
abstract void | add(int field, int amount)
Adds the specified amount of time to the given time field. |
boolean | after(Object o)
Compares the given calendar with this. |
boolean | before(Object o)
Compares the given calendar with this. |
void | clear()
Clears the values of all the time fields. |
void | clear(int field)
Clears the values of the specified time field. |
Object | clone()
Return a clone of this object. |
int | compareTo(Calendar cal)
Compares the time of two calendar instances. |
protected void | complete()
Fills any unset fields in the time field list |
protected abstract void | computeFields()
Converts the milliseconds since the epoch UTC
( time ) to time fields
(fields ). |
protected abstract void | computeTime()
Converts the time field values ( fields ) to
milliseconds since the epoch UTC (time ). |
boolean | equals(Object o)
Compares the given calendar with this. |
int | get(int field)
Gets the value of the specified field. |
int | getActualMaximum(int field)
Gets the actual maximum value that is allowed for the specified field.
|
int | getActualMinimum(int field)
Gets the actual minimum value that is allowed for the specified field.
|
static Locale[] | getAvailableLocales()
Gets the set of locales for which a Calendar is available. |
String | getDisplayName(int field, int style, Locale locale)
Returns a localised textual representation of the current value
of the given field using the specified style. |
Map<String,Integer> | getDisplayNames(int field, int style, Locale locale)
Returns a map linking all specified textual representations
of the given field to their numerical values. |
int | getFirstDayOfWeek()
Gets what the first day of week is. |
abstract int | getGreatestMinimum(int field)
Gets the greatest minimum value that is allowed for the specified field. |
static Calendar | getInstance()
Creates a calendar representing the actual time, using the default
time zone and locale.
|
static Calendar | getInstance(TimeZone zone)
Creates a calendar representing the actual time, using the given
time zone and the default locale.
|
static Calendar | getInstance(Locale locale)
Creates a calendar representing the actual time, using the default
time zone and the given locale.
|
static Calendar | getInstance(TimeZone zone, Locale locale)
Creates a calendar representing the actual time, using the given
time zone and locale.
|
abstract int | getLeastMaximum(int field)
Gets the smallest maximum value that is allowed for the
specified field. |
abstract int | getMaximum(int field)
Gets the biggest value that is allowed for the specified field. |
int | getMinimalDaysInFirstWeek()
Gets how many days are required in the first week of the year. |
abstract int | getMinimum(int field)
Gets the smallest value that is allowed for the specified field. |
Date | getTime()
Converts the time represented by this object to a
Date -Object. |
long | getTimeInMillis()
Returns the time represented by this Calendar. |
TimeZone | getTimeZone()
Gets the time zone of this calendar |
int | hashCode()
Returns a hash code for this calendar. |
protected int | internalGet(int field)
Gets the value of the specified field. |
boolean | isLenient()
Tells if the date/time interpretation is lenient. |
boolean | isSet(int field)
Determines if the specified field has a valid value. |
abstract void | roll(int field, boolean up)
Rolls the specified time field up or down. |
void | roll(int field, int amount)
Rolls up or down the specified time field by the given amount.
|
void | set(int field, int value)
Sets the time field with the given value. |
void | set(int year, int month, int date)
Sets the fields for year, month, and date |
void | set(int year, int month, int date, int hour, int minute)
Sets the fields for year, month, date, hour, and minute |
void | set(int year, int month, int date, int hour, int minute, int second)
Sets the fields for year, month, date, hour, and minute |
void | setFirstDayOfWeek(int value)
Sets what the first day of week is. |
void | setLenient(boolean lenient)
Specifies if the date/time interpretation should be lenient.
|
void | setMinimalDaysInFirstWeek(int value)
Sets how many days are required in the first week of the year.
|
void | setTime(Date date)
Sets this Calendar's time to the given Date. |
void | setTimeInMillis(long time)
Sets this Calendar's time to the given Time. |
void | setTimeZone(TimeZone zone)
Sets the time zone to the specified value. |
String | toString()
Returns a string representation of this object. |
Since: 1.6
Serial:
Serial:
Serial:
Serial:
Since: 1.6
Since: 1.6
Serial:
See Also: Calendar
See Also: Calendar
Parameters: zone a time zone. locale a locale.
Parameters: field the time field. One of the time field constants. amount the amount of time.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Parameters: o the object to that we should compare.
Returns: true, if the given object is a calendar, and this calendar represents a bigger time than the calendar o.
Throws: ClassCastException if o is not an calendar.
Since: JDK1.2 you don't need to override this method
Parameters: o the object to that we should compare.
Returns: true, if the given object is a calendar, and this calendar represents a smaller time than the calendar o.
Throws: ClassCastException if o is not an calendar.
Since: JDK1.2 you don't need to override this method
Parameters: field the time field. One of the time field constants.
Throws: ArrayIndexOutOfBoundsException if field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Parameters: calendar the calendar to which the time should be compared. cal the calendar to compare this instance with.
Returns: 0 if the two calendars are set to the same time,
less than 0 if the time of this calendar is before that of
cal
, or more than 0 if the time of this calendar is after
that of cal
.
Throws: NullPointerException if cal
is null. IllegalArgumentException if either calendar has fields set to
invalid values.
Since: 1.5
time
) to time fields
(fields
). Override this method if you write your
own Calendar.fields
) to
milliseconds since the epoch UTC (time
). Override
this method if you write your own Calendar.Parameters: o the object to that we should compare.
Returns: true, if the given object is a calendar, that represents the same time (but doesn't necessary have the same fields).
Parameters: field the time field. One of the time field constants.
Returns: the value of the specified field
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
UNKNOWN: Not final since JDK 1.4
Parameters: field the time field. One of the time field constants.
Returns: the actual maximum value.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Since: jdk1.2
Parameters: field the time field. One of the time field constants.
Returns: the actual minimum value.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Since: jdk1.2
Returns: the set of locales.
Throws: MissingResourceException if locale data couldn't be found.
null
is returned. If one does exist,
then the value is obtained from {@link #get(int)} and converted
appropriately. For example, if the MONTH
field is
requested, then get(MONTH)
is called. This is then
converted to a textual representation based on its value and
the style requested; if the LONG
style is requested
and the returned value is 11
from a
{@link GregorianCalendar} implementation, then "December"
is returned. By default, a textual representation is available
for all fields which have an applicable value obtainable from
{@link java.text.DateFormatSymbols}.
Parameters: field the calendar field whose textual representation should be obtained. style the style to use; either {@link #LONG} or {@link #SHORT}. locale the locale to use for translation.
Returns: the textual representation of the given field in the specified
style, or null
if none is applicable.
Throws: IllegalArgumentException if field
or style
or invalid, or the calendar is non-lenient
and has invalid values. NullPointerException if locale
is null
.
Since: 1.6
LONG
is specified and the German locale, then the map will
contain "Montag" to {@link #MONDAY}, "Dienstag" to
{@link #TUESDAY}, "Mittwoch" to {@link #WEDNESDAY} and
so on. The default implementation uses the values returned
by {@link DateFormatSymbols} so, for example, the style
{@link #ALL_STYLES} and the field {@link #MONTH} will return
a map filled with the values returned from
{@link DateFormatSymbols#getMonths()} and
{@link DateFormatSymbols#getShortMonths()}. If there are
no textual representations for a given field (usually because
it is purely numeric, such as the year in the
{@link GregorianCalendar}), null
is returned.
Parameters: field the calendar field whose textual representation should be obtained. style the style to use; either {@link #LONG}, {@link #SHORT} or {@link ALL_STYLES}. locale the locale to use for translation.
Returns: a map of the textual representations of the given field in the
specified style to their numeric values, or null
if none is applicable.
Throws: IllegalArgumentException if field
or style
or invalid, or the calendar is non-lenient
and has invalid values. NullPointerException if locale
is null
.
Since: 1.6
Returns: the first day of week. One of SUNDAY to SATURDAY.
Parameters: field the time field. One of the time field constants.
Returns: the greatest minimum value.
Returns: The new calendar.
Parameters: zone a time zone (null
not permitted).
Returns: The new calendar.
Throws: NullPointerException if zone
is null
.
Parameters: locale a locale (null
not permitted).
Returns: The new calendar.
Throws: NullPointerException if locale
is null
.
Parameters: zone a time zone (null
not permitted). locale a locale (null
not permitted).
Returns: The new calendar.
Throws: NullPointerException if zone
or locale
is null
.
Parameters: field the time field. One of the time field constants.
Returns: the least maximum value.
Parameters: field the time field. One of the time field constants.
Returns: the biggest value.
Returns: the minimal days required in the first week.
See Also: Calendar
Parameters: field the time field. One of the time field constants.
Returns: the smallest value.
Date
-Object.Returns: the Date.
Returns: the time in milliseconds since the epoch.
UNKNOWN: This was made public in 1.4.
Returns: the current time zone.
Returns: a hash code, which fullfits the general contract of
hashCode()
Parameters: field the time field. One of the time field constants.
Returns: the value of the specified field, undefined if
areFieldsSet
or isSet[field]
is false.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Returns: true, if the date should be interpreted linient, false if it should be interpreted strict.
Returns: true if the specified field has a value.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Parameters: field the time field. One of the time field constants. up the direction, true for up, false for down.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
roll(int, boolean)
for the specified amount.
Subclasses should override this method to do more intuitiv things.
Parameters: field the time field. One of the time field constants. amount the amount to roll by, positive for rolling up, negative for rolling down.
Throws: ArrayIndexOutOfBoundsException if the field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
Since: JDK1.2
Parameters: field the time field. One of the time field constants value the value to be set.
Throws: ArrayIndexOutOfBoundsException if field is outside
the valid range. The value of field must be >= 0 and
<= FIELD_COUNT
.
UNKNOWN: Not final since JDK 1.4
Parameters: year the year. month the month, one of the constants JANUARY..UNDICEMBER. date the day of the month
Parameters: year the year. month the month, one of the constants JANUARY..UNDICEMBER. date the day of the month hour the hour of day. minute the minute.
Parameters: year the year. month the month, one of the constants JANUARY..UNDICEMBER. date the day of the month hour the hour of day. minute the minute. second the second.
Parameters: value the first day of week. One of SUNDAY to SATURDAY.
Parameters: lenient true, if the date should be interpreted linient, false if it should be interpreted strict.
Parameters: value the minimal days required in the first week.
Parameters: date the date (null
not permitted).
Throws: NullPointerException if date
is null
.
Parameters: time the time in milliseconds since the epoch
UNKNOWN: This was made public in 1.4.
Parameters: zone the new time zone