java.util

Class Calendar

Implemented Interfaces:
Cloneable, Comparable<T>, Serializable
Known Direct Subclasses:
GregorianCalendar

public abstract class Calendar
extends Object
implements Serializable, Cloneable, Comparable<T>

This class is an abstract base class for Calendars, which can be used to convert between 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.
This class is locale sensitive. To get the Object matching the current locale you can use getInstance. You can even provide a locale or a timezone. getInstance returns currently a GregorianCalendar for the current date.
If you want to convert a date from the Year, Month, Day, DayOfWeek, etc. Representation to a 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().
If you want to convert a Date-object to the Calendar representation, create a new Calendar, assign the Date-Object with setTime(), and read the fields with get(int).
When computing the date from time fields, it may happen, that there are either two few fields set, or some fields are inconsistent. This cases will handled in a calendar specific way. Missing fields are replaced by the fields of the epoch: 1970 January 1 00:00.
To understand, how the day of year is computed out of the fields look at the following table. It is traversed from top to bottom, and for the first line all fields are set, that line is used to compute the day.
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_year
The hour_of_day-field takes precedence over the ampm and hour_of_ampm fields.
Note: This can differ for non-Gregorian calendar.
To convert a calendar to a human readable form and vice versa, use the java.text.DateFormat class.
Other useful things you can do with an calendar, is rolling fields (that means increase/decrease a specific field by one, propagating overflows), or adding/substracting a fixed amount to a field.
See Also:
Date, GregorianCalendar, TimeZone, DateFormat, Serialized Form

Field Summary

static int
ALL_STYLES
A style specifier for 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.
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.
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.
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 getDisplayName(int,int,Locale) and 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 getDisplayName(int,int,Locale) and getDisplayNames(int,int,Locale) stating that names should be returned in their short variant if applicable.
static int
SUNDAY
Constant representing Sunday.
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.
protected boolean
areFieldsSet
Tells if the fields have a valid value.
protected int[]
fields
The time fields.
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.
protected long
time
The time in milliseconds since the epoch.

Constructor Summary

Calendar()
Constructs a new Calendar with the default time zone and the default locale.
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
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(Locale locale)
Creates a calendar representing the actual time, using the default time zone and the given 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(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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ALL_STYLES

public static final int ALL_STYLES
A style specifier for getDisplayNames(int,int,Locale) stating that names should be returned in both long and short variants.
Field Value:
0
Since:
1.6
See Also:
SHORT, LONG

AM

public static final int AM
Useful constant for 12-hour clock.
Field Value:
0

AM_PM

public static final int AM_PM
Constant representing the part of the day for 12-hour clock. This should be one of AM or PM.
Field Value:
9

APRIL

public static final int APRIL
Constant representing April.
Field Value:
3

AUGUST

public static final int AUGUST
Constant representing August.
Field Value:
7

DATE

public static final int DATE
Constant representing the day time field, synonym for DAY_OF_MONTH.
Field Value:
5

DAY_OF_MONTH

public static final int DAY_OF_MONTH
Constant representing the day time field.
Field Value:
5

DAY_OF_WEEK

public static final int DAY_OF_WEEK
Constant representing the day of week time field. This field should contain one of the SUNDAY,...,SATURDAY constants below.
Field Value:
7

DAY_OF_WEEK_IN_MONTH

public static final int DAY_OF_WEEK_IN_MONTH
Constant representing the day-of-week-in-month field. For instance this field contains 2 for the second thursday in a month. If you give a negative number here, the day will count from the end of the month.
Field Value:
8

DAY_OF_YEAR

public static final int DAY_OF_YEAR
Constant representing the day of year time field. This is 1 for the first day in month.
Field Value:
6

DECEMBER

public static final int DECEMBER
Constant representing December.
Field Value:
11

DST_OFFSET

public static final int DST_OFFSET
Constant representing the daylight saving time offset in milliseconds. The default is the value given by the time zone.
Field Value:
16

ERA

public static final int ERA
Constant representing the era time field.
Field Value:
0

FEBRUARY

public static final int FEBRUARY
Constant representing February.
Field Value:
1

FIELD_COUNT

public static final int FIELD_COUNT
Number of time fields.
Field Value:
17

FRIDAY

public static final int FRIDAY
Constant representing Friday.
Field Value:
6

HOUR

public static final int HOUR
Constant representing the hour time field for 12-hour clock.
Field Value:
10

HOUR_OF_DAY

public static final int HOUR_OF_DAY
Constant representing the hour of day time field for 24-hour clock.
Field Value:
11

JANUARY

public static final int JANUARY
Constant representing January.
Field Value:
0

JULY

public static final int JULY
Constant representing July.
Field Value:
6

JUNE

public static final int JUNE
Constant representing June.
Field Value:
5

LONG

public static final int LONG
A style specifier for getDisplayName(int,int,Locale) and getDisplayNames(int,int,Locale) stating that names should be returned in their long variant if applicable.
Field Value:
2
Since:
1.6

MARCH

public static final int MARCH
Constant representing March.
Field Value:
2

MAY

public static final int MAY
Constant representing May.
Field Value:
4

MILLISECOND

public static final int MILLISECOND
Constant representing the millisecond time field.
Field Value:
14

MINUTE

public static final int MINUTE
Constant representing the minute of hour time field.
Field Value:
12

MONDAY

public static final int MONDAY
Constant representing Monday.
Field Value:
2

MONTH

public static final int MONTH
Constant representing the month time field. This field should contain one of the JANUARY,...,DECEMBER constants below.
Field Value:
2

NOVEMBER

public static final int NOVEMBER
Constant representing November.
Field Value:
10

OCTOBER

public static final int OCTOBER
Constant representing October.
Field Value:
9

PM

public static final int PM
Useful constant for 12-hour clock.
Field Value:
1

SATURDAY

public static final int SATURDAY
Constant representing Saturday.
Field Value:
7

SECOND

public static final int SECOND
Constant representing the second time field.
Field Value:
13

SEPTEMBER

public static final int SEPTEMBER
Constant representing September.
Field Value:
8

SHORT

public static final int SHORT
A style specifier for getDisplayName(int,int,Locale) and getDisplayNames(int,int,Locale) stating that names should be returned in their short variant if applicable.
Field Value:
1
Since:
1.6

SUNDAY

public static final int SUNDAY
Constant representing Sunday.
Field Value:
1

THURSDAY

public static final int THURSDAY
Constant representing Thursday.
Field Value:
5

TUESDAY

public static final int TUESDAY
Constant representing Tuesday.
Field Value:
3

UNDECIMBER

public static final int UNDECIMBER
Constant representing Undecimber. This is an artificial name useful for lunar calendars.
Field Value:
12

WEDNESDAY

public static final int WEDNESDAY
Constant representing Wednesday.
Field Value:
4

WEEK_OF_MONTH

public static final int WEEK_OF_MONTH
Constant representing the week of the month time field.
Field Value:
4

WEEK_OF_YEAR

public static final int WEEK_OF_YEAR
Constant representing the week of the year field.
Field Value:
3

YEAR

public static final int YEAR
Constant representing the year time field.
Field Value:
1

ZONE_OFFSET

public static final int ZONE_OFFSET
Constant representing the time zone offset time field for the time given in the other fields. It is measured in milliseconds. The default is the offset of the time zone.
Field Value:
15

areFieldsSet

protected boolean areFieldsSet
Tells if the fields have a valid value. This superseeds the isSet array.

fields

protected int[] fields
The time fields. The array is indexed by the constants YEAR to DST_OFFSET.

isSet

protected boolean[] isSet
The flags which tell if the fields above have a value.

isTimeSet

protected boolean isTimeSet
Tells if the above field has a valid value.

time

protected long time
The time in milliseconds since the epoch.

Constructor Details

Calendar

protected Calendar()
Constructs a new Calendar with the default time zone and the default locale.

Calendar

protected Calendar(TimeZone zone,
                   Locale locale)
Constructs a new Calendar with the given time zone and the given locale.
Parameters:
zone - a time zone.
locale - a locale.

Method Details

add

public abstract void add(int field,
                         int amount)
Adds the specified amount of time to the given time field. The amount may be negative to subtract the time. If the field overflows it does what you expect: Jan, 25 + 10 Days is Feb, 4.
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.

after

public boolean after(Object o)
Compares the given calendar with this.
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

before

public boolean before(Object o)
Compares the given calendar with this.
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

clear

public final void clear()
Clears the values of all the time fields.

clear

public final void clear(int field)
Clears the values of the specified time field.
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.

clone

public Object clone()
Return a clone of this object.
Overrides:
clone in interface Object

compareTo

public int compareTo(Calendar cal)
Compares the time of two calendar instances.
Parameters:
cal - the calendar to which the time should be compared.
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

complete

protected void complete()
Fills any unset fields in the time field list

computeFields

protected abstract void computeFields()
Converts the milliseconds since the epoch UTC (time) to time fields (fields). Override this method if you write your own Calendar.

computeTime

protected abstract void computeTime()
Converts the time field values (fields) to milliseconds since the epoch UTC (time). Override this method if you write your own Calendar.

equals

public boolean equals(Object o)
Compares the given calendar with this.
Overrides:
equals in interface Object
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).

get

public int get(int field)
Gets the value of the specified field. They are recomputed if they are invalid.
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.

getActualMaximum

public int getActualMaximum(int field)
Gets the actual maximum value that is allowed for the specified field. This value is dependent on the values of the other fields.
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

getActualMinimum

public int getActualMinimum(int field)
Gets the actual minimum value that is allowed for the specified field. This value is dependent on the values of the other fields.
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

getAvailableLocales

public static Locale[] getAvailableLocales()
Gets the set of locales for which a Calendar is available.
Returns:
the set of locales.
Throws:
MissingResourceException - if locale data couldn't be found.

getDisplayName

public 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. If there is no applicable textual representation (e.g. the field has a numeric value), then null is returned. If one does exist, then the value is obtained from 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 GregorianCalendar implementation, then "December" is returned. By default, a textual representation is available for all fields which have an applicable value obtainable from DateFormatSymbols.
Parameters:
field - the calendar field whose textual representation should be obtained.
style - the style to use; either LONG or 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

getDisplayNames

public Map getDisplayNames(int field,
                                           int style,
                                           Locale locale)
Returns a map linking all specified textual representations of the given field to their numerical values. The textual representations included are determined by the specified style and locale. For example, if the style LONG is specified and the German locale, then the map will contain "Montag" to MONDAY, "Dienstag" to TUESDAY, "Mittwoch" to WEDNESDAY and so on. The default implementation uses the values returned by DateFormatSymbols so, for example, the style ALL_STYLES and the field MONTH will return a map filled with the values returned from DateFormatSymbols.getMonths() and DateFormatSymbols.getShortMonths(). If there are no textual representations for a given field (usually because it is purely numeric, such as the year in the GregorianCalendar), null is returned.
Parameters:
field - the calendar field whose textual representation should be obtained.
style - the style to use; either LONG, SHORT or 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

getFirstDayOfWeek

public int getFirstDayOfWeek()
Gets what the first day of week is. This is used for WEEK_OF_MONTH and WEEK_OF_YEAR fields.
Returns:
the first day of week. One of SUNDAY to SATURDAY.

getGreatestMinimum

public abstract int getGreatestMinimum(int field)
Gets the greatest minimum value that is allowed for the specified field.
Parameters:
field - the time field. One of the time field constants.
Returns:
the greatest minimum value.

getInstance

public static Calendar getInstance()
Creates a calendar representing the actual time, using the default time zone and locale.
Returns:
The new calendar.

getInstance

public static Calendar getInstance(Locale locale)
Creates a calendar representing the actual time, using the default time zone and the given locale.
Parameters:
locale - a locale (null not permitted).
Returns:
The new calendar.
Throws:
NullPointerException - if locale is null.

getInstance

public static Calendar getInstance(TimeZone zone)
Creates a calendar representing the actual time, using the given time zone and the default locale.
Parameters:
zone - a time zone (null not permitted).
Returns:
The new calendar.
Throws:
NullPointerException - if zone is null.

getInstance

public static Calendar getInstance(TimeZone zone,
                                   Locale locale)
Creates a calendar representing the actual time, using the given time zone and locale.
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.

getLeastMaximum

public abstract int getLeastMaximum(int field)
Gets the smallest maximum value that is allowed for the specified field. For example this is 28 for DAY_OF_MONTH.
Parameters:
field - the time field. One of the time field constants.
Returns:
the least maximum value.

getMaximum

public abstract int getMaximum(int field)
Gets the biggest value that is allowed for the specified field.
Parameters:
field - the time field. One of the time field constants.
Returns:
the biggest value.

getMinimalDaysInFirstWeek

public int getMinimalDaysInFirstWeek()
Gets how many days are required in the first week of the year.
Returns:
the minimal days required in the first week.

getMinimum

public abstract int getMinimum(int field)
Gets the smallest value that is allowed for the specified field.
Parameters:
field - the time field. One of the time field constants.
Returns:
the smallest value.

getTime

public final Date getTime()
Converts the time represented by this object to a Date-Object.
Returns:
the Date.

getTimeInMillis

public long getTimeInMillis()
Returns the time represented by this Calendar.
Returns:
the time in milliseconds since the epoch.

getTimeZone

public TimeZone getTimeZone()
Gets the time zone of this calendar
Returns:
the current time zone.

hashCode

public int hashCode()
Returns a hash code for this calendar.
Overrides:
hashCode in interface Object
Returns:
a hash code, which fullfits the general contract of hashCode()

internalGet

protected final int internalGet(int field)
Gets the value of the specified field. This method doesn't recompute the fields, if they are invalid.
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.

isLenient

public boolean isLenient()
Tells if the date/time interpretation is lenient.
Returns:
true, if the date should be interpreted linient, false if it should be interpreted strict.

isSet

public final boolean isSet(int field)
Determines if the specified field has a valid value.
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.

roll

public abstract void roll(int field,
                          boolean up)
Rolls the specified time field up or down. This means add one to the specified field, but don't change the other fields. If the maximum for this field is reached, start over with the minimum value.
Note: There may be situation, where the other fields must be changed, e.g rolling the month on May, 31. The date June, 31 is automatically converted to July, 1.
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

public void roll(int field,
                 int amount)
Rolls up or down the specified time field by the given amount. A negative amount rolls down. The default implementation is call 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

set

public void set(int field,
                int value)
Sets the time field with the given value. This does invalidate the time in milliseconds.
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.

set

public final void set(int year,
                      int month,
                      int date)
Sets the fields for year, month, and date
Parameters:
year - the year.
month - the month, one of the constants JANUARY..UNDICEMBER.
date - the day of the month

set

public final void set(int year,
                      int month,
                      int date,
                      int hour,
                      int minute)
Sets the fields for year, month, date, hour, and 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.

set

public final void set(int year,
                      int month,
                      int date,
                      int hour,
                      int minute,
                      int second)
Sets the fields for year, month, date, hour, and 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.

setFirstDayOfWeek

public void setFirstDayOfWeek(int value)
Sets what the first day of week is. This is used for WEEK_OF_MONTH and WEEK_OF_YEAR fields.
Parameters:
value - the first day of week. One of SUNDAY to SATURDAY.

setLenient

public void setLenient(boolean lenient)
Specifies if the date/time interpretation should be lenient. If the flag is set, a date such as "February 30, 1996" will be treated as the 29th day after the February 1. If this flag is false, such dates will cause an exception.
Parameters:
lenient - true, if the date should be interpreted linient, false if it should be interpreted strict.

setMinimalDaysInFirstWeek

public void setMinimalDaysInFirstWeek(int value)
Sets how many days are required in the first week of the year. If the first day of the year should be the first week you should set this value to 1. If the first week must be a full week, set it to 7.
Parameters:
value - the minimal days required in the first week.

setTime

public final void setTime(Date date)
Sets this Calendar's time to the given Date. All time fields are invalidated by this method.
Parameters:
date - the date (null not permitted).
Throws:
NullPointerException - if date is null.

setTimeInMillis

public void setTimeInMillis(long time)
Sets this Calendar's time to the given Time. All time fields are invalidated by this method.
Parameters:
time - the time in milliseconds since the epoch

setTimeZone

public void setTimeZone(TimeZone zone)
Sets the time zone to the specified value.
Parameters:
zone - the new time zone

toString

public String toString()
Returns a string representation of this object. It is mainly for debugging purposes and its content is implementation specific.
Overrides:
toString in interface Object

Calendar.java -- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.