java.util
public
abstract
class
java.util.Calendar
Calendar is an abstract class which provides the conversion between Dates and
integer calendar fields, such as the month, year or minute. Subclasses of
this class implement a specific calendar type, such as the gregorian
calendar.
Known Direct Subclasses
GregorianCalendar |
GregorianCalendar provides the conversion between Dates and integer calendar
fields, such as the month, year or minute, for the Gregorian calendar. |
Summary
Constants
Fields
protected |
|
|
boolean |
areFieldsSet |
Set to true when the calendar fields have been set from the time, set to
false when a field is changed and the fields must be recomputed. |
protected |
|
|
int[] |
fields |
An integer array of calendar fields. |
protected |
|
|
boolean[] |
isSet |
|
protected |
|
|
boolean |
isTimeSet |
Set to true when the time has been set, set to false when a field is
changed and the time must be recomputed. |
protected |
|
|
long |
time |
The time in milliseconds since January 1, 1970. |
Protected Constructors
Public Methods
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() |
|
|
|
|
|
int |
compareTo(Calendar anotherCalendar) |
|
|
|
|
|
boolean |
equals(Object object) |
|
|
|
|
|
int |
get(int field) |
|
|
|
|
|
int |
getActualMaximum(int field) |
|
|
|
|
|
int |
getActualMinimum(int field) |
|
synchronized |
|
static |
|
Locale[] |
getAvailableLocales() |
|
|
|
|
|
int |
getFirstDayOfWeek() |
abstract |
|
|
|
|
int |
getGreatestMinimum(int field) |
|
synchronized |
|
static |
|
Calendar |
getInstance(TimeZone timezone, Locale locale) |
|
synchronized |
|
static |
|
Calendar |
getInstance() |
|
synchronized |
|
static |
|
Calendar |
getInstance(TimeZone timezone) |
|
synchronized |
|
static |
|
Calendar |
getInstance(Locale locale) |
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) |
|
|
final |
|
|
void |
set(int year, int month, int day, int hourOfDay, int minute) |
|
|
|
|
|
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, 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() |
Protected Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
AM
Constant Value:
0
(0x00000000)
public
static
final
int
AM_PM
Constant Value:
9
(0x00000009)
public
static
final
int
APRIL
Constant Value:
3
(0x00000003)
public
static
final
int
AUGUST
Constant Value:
7
(0x00000007)
public
static
final
int
DATE
Constant Value:
5
(0x00000005)
public
static
final
int
DAY_OF_MONTH
Constant Value:
5
(0x00000005)
public
static
final
int
DAY_OF_WEEK
Constant Value:
7
(0x00000007)
public
static
final
int
DAY_OF_WEEK_IN_MONTH
Constant Value:
8
(0x00000008)
public
static
final
int
DAY_OF_YEAR
Constant Value:
6
(0x00000006)
public
static
final
int
DECEMBER
Constant Value:
11
(0x0000000b)
public
static
final
int
DST_OFFSET
Constant Value:
16
(0x00000010)
public
static
final
int
ERA
Constant Value:
0
(0x00000000)
public
static
final
int
FEBRUARY
Constant Value:
1
(0x00000001)
public
static
final
int
FIELD_COUNT
Constant Value:
17
(0x00000011)
public
static
final
int
FRIDAY
Constant Value:
6
(0x00000006)
public
static
final
int
HOUR
Constant Value:
10
(0x0000000a)
public
static
final
int
HOUR_OF_DAY
Constant Value:
11
(0x0000000b)
public
static
final
int
JANUARY
Constant Value:
0
(0x00000000)
public
static
final
int
JULY
Constant Value:
6
(0x00000006)
public
static
final
int
JUNE
Constant Value:
5
(0x00000005)
public
static
final
int
MARCH
Constant Value:
2
(0x00000002)
public
static
final
int
MAY
Constant Value:
4
(0x00000004)
public
static
final
int
MILLISECOND
Constant Value:
14
(0x0000000e)
public
static
final
int
MINUTE
Constant Value:
12
(0x0000000c)
public
static
final
int
MONDAY
Constant Value:
2
(0x00000002)
public
static
final
int
MONTH
Constant Value:
2
(0x00000002)
public
static
final
int
NOVEMBER
Constant Value:
10
(0x0000000a)
public
static
final
int
OCTOBER
Constant Value:
9
(0x00000009)
public
static
final
int
PM
Constant Value:
1
(0x00000001)
public
static
final
int
SATURDAY
Constant Value:
7
(0x00000007)
public
static
final
int
SECOND
Constant Value:
13
(0x0000000d)
public
static
final
int
SEPTEMBER
Constant Value:
8
(0x00000008)
public
static
final
int
SUNDAY
Constant Value:
1
(0x00000001)
public
static
final
int
THURSDAY
Constant Value:
5
(0x00000005)
public
static
final
int
TUESDAY
Constant Value:
3
(0x00000003)
public
static
final
int
UNDECIMBER
Constant Value:
12
(0x0000000c)
public
static
final
int
WEDNESDAY
Constant Value:
4
(0x00000004)
public
static
final
int
WEEK_OF_MONTH
Constant Value:
4
(0x00000004)
public
static
final
int
WEEK_OF_YEAR
Constant Value:
3
(0x00000003)
public
static
final
int
YEAR
Constant Value:
1
(0x00000001)
public
static
final
int
ZONE_OFFSET
Constant Value:
15
(0x0000000f)
Fields
protected
boolean
areFieldsSet
Set to true when the calendar fields have been set from the time, set to
false when a field is changed and the fields must be recomputed.
protected
int[]
fields
An integer array of calendar fields.
protected
boolean[]
isSet
protected
boolean
isTimeSet
Set to true when the time has been set, set to false when a field is
changed and the time must be recomputed.
protected
long
time
The time in milliseconds since January 1, 1970.
Protected Constructors
protected
Calendar()
Initializes this Calendar instance using the default TimeZone and Locale.
protected
Calendar(TimeZone timezone, Locale locale)
Initializes this Calendar instance using the specified TimeZone and
Locale.
Parameters
timezone
| the timezone |
locale
| the locale
|
Public Methods
public
abstract
void
add(int field, int value)
Adds the specified amount to a Calendar field.
Parameters
field
| the Calendar field to modify |
value
| the amount to add to the field |
public
boolean
after(Object calendar)
Returns if the Date specified by this Calendar instance is after the Date
specified by the parameter. The comparison is not dependent on the
time zones of the Calendars.
Parameters
calendar
| the Calendar instance to compare |
Returns
- true when this Calendar is after calendar, false otherwise
public
boolean
before(Object calendar)
Returns if the Date specified by this Calendar instance is before the
Date specified by the parameter. The comparison is not dependent on the
time zones of the Calendars.
Parameters
calendar
| the Calendar instance to compare |
Returns
- true when this Calendar is before calendar, false otherwise
public
final
void
clear()
Clears all of the fields of this Calendar. All fields are initialized to
zero.
public
final
void
clear(int field)
Clears the specified field to zero.
public
Object
clone()
Returns a new Calendar with the same properties.
Returns
- a shallow copy of this Calendar
public
int
compareTo(Calendar anotherCalendar)
Compares the times of the two Calendars, which represent the milliseconds
from the January 1, 1970 00:00:00.000 GMT (Gregorian).
Parameters
anotherCalendar
| another calendar that is compared with. |
Returns
- 0 if the times of the two calendar are equal, -1 if the time of
this calendar is before the other one, 1 if the time of this
calendar is after the other one.
public
boolean
equals(Object object)
Compares the specified object to this Calendar and answer if they are
equal. The object must be an instance of Calendar and have the same
properties.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this Calendar, false
otherwise
public
int
get(int field)
Gets the value of the specified field after computing the field values
from the time if required.
Returns
- the value of the specified field
Throws
IllegalArgumentException
| when the fields are not set, the time is not set, and the
time cannot be computed from the current field values
|
public
int
getActualMaximum(int field)
Gets the maximum value of the specified field for the current date.
Returns
- the maximum value of the specified field
public
int
getActualMinimum(int field)
Gets the minimum value of the specified field for the current date.
Returns
- the minimum value of the specified field
public
static
synchronized
Locale[]
getAvailableLocales()
Gets the list of installed Locales which support Calendar.
public
int
getFirstDayOfWeek()
Gets the first day of the week for this Calendar.
Returns
- a Calendar day of the week
public
abstract
int
getGreatestMinimum(int field)
Gets the greatest minimum value of the specified field.
Returns
- the greatest minimum value of the specified field
public
static
synchronized
Calendar
getInstance(TimeZone timezone, Locale locale)
Constructs a new instance of the Calendar subclass appropriate for the
specified Locale.
Parameters
timezone
| the timezone to use |
locale
| the locale to use |
Returns
- a Calendar subclass instance set to the current date and time in
the specified timezone
public
static
synchronized
Calendar
getInstance()
Constructs a new instance of the Calendar subclass appropriate for the
default Locale.
Returns
- a Calendar subclass instance set to the current date and time in
the default timezone
public
static
synchronized
Calendar
getInstance(TimeZone timezone)
Constructs a new instance of the Calendar subclass appropriate for the
default Locale, using the specified TimeZone.
Parameters
timezone
| the timezone to use |
Returns
- a Calendar subclass instance set to the current date and time in
the specified timezone
public
static
synchronized
Calendar
getInstance(Locale locale)
Constructs a new instance of the Calendar subclass appropriate for the
specified Locale.
Returns
- a Calendar subclass instance set to the current date and time
public
abstract
int
getLeastMaximum(int field)
Gets the smallest maximum value of the specified field.
Returns
- the smallest maximum value of the specified field
public
abstract
int
getMaximum(int field)
Gets the greatest maximum value of the specified field.
Returns
- the greatest maximum value of the specified field
public
int
getMinimalDaysInFirstWeek()
Gets the minimal days in the first week of the year.
Returns
- the minimal days in the first week of the year
public
abstract
int
getMinimum(int field)
Gets the smallest minimum value of the specified field.
Returns
- the smallest minimum value of the specified field
public
final
Date
getTime()
Gets the time of this Calendar as a Date object.
Returns
- a new Date initialized to the time of this Calendar
public
long
getTimeInMillis()
Computes the time from the fields if required and returns the time.
Returns
- the time of this Calendar
public
TimeZone
getTimeZone()
Gets the timezone of this Calendar.
Returns
- the timezone used by this Calendar
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isLenient()
Returns if this Calendar accepts field values which are outside the valid
range for the field.
Returns
- true if this Calendar is lenient, false otherwise
public
final
boolean
isSet(int field)
Returns if the specified field is set.
Returns
- true if the specified field is set, false otherwise
public
void
roll(int field, int value)
Adds the specified amount 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.
Parameters
field
| the field to roll |
value
| the amount to add
|
public
abstract
void
roll(int field, boolean increment)
Increment or decrement the specified field and wrap the value of the
field when it goes beyond the maximum or minimum value for the current
date. Other fields will be adjusted as required to maintain a consistent
date.
Parameters
field
| the field to roll |
increment
| true to increment the field, false to decrement
|
public
final
void
set(int year, int month, int day, int hourOfDay, int minute)
Sets the year, month, day of the month, hour of day and minute fields.
Parameters
year
| the year |
month
| the month |
day
| the day of the month |
hourOfDay
| the hour of day |
minute
| the minute
|
public
void
set(int field, int value)
Sets a field to the specified value.
Parameters
field
| the Calendar field to modify |
value
| the value
|
public
final
void
set(int year, int month, int day)
Sets the year, month and day of the month fields.
Parameters
year
| the year |
month
| the month |
day
| the day of the month
|
public
final
void
set(int year, int month, int day, int hourOfDay, int minute, int second)
Sets the year, month, day of the month, hour of day, minute and second
fields.
Parameters
year
| the year |
month
| the month |
day
| the day of the month |
hourOfDay
| the hour of day |
minute
| the minute |
second
| the second
|
public
void
setFirstDayOfWeek(int value)
Sets the first day of the week for this Calendar.
Parameters
value
| a Calendar day of the week
|
public
void
setLenient(boolean value)
Sets this Calendar to accept field values which are outside the valid
range for the field.
public
void
setMinimalDaysInFirstWeek(int value)
Sets the minimal days in the first week of the year.
Parameters
value
| the minimal days in the first week of the year
|
public
final
void
setTime(Date date)
Sets the time of this Calendar.
public
void
setTimeInMillis(long milliseconds)
Sets the time of this Calendar.
Parameters
milliseconds
| the time as the number of milliseconds since Jan. 1, 1970
|
public
void
setTimeZone(TimeZone timezone)
Sets the timezone used by this Calendar.
public
String
toString()
Returns the string representation of this Calendar.
Returns
- the string representation of this Calendar
Protected Methods
protected
void
complete()
Computes the time from the fields if the time has not already been set.
Computes the fields from the time if the fields are not already set.
protected
abstract
void
computeFields()
Computes the Calendar fields from the time.
protected
abstract
void
computeTime()
Computes the time from the Calendar fields.
protected
final
int
internalGet(int field)
Gets the value of the specified field without recomputing.
Returns
- the value of the specified field