java.util.GregorianCalendar
GregorianCalendar provides the conversion between Dates and integer calendar
fields, such as the month, year or minute, for the Gregorian calendar. See
Calendar for the defined fields.
Summary
Constants
|
|
|
Value |
|
int |
AD |
Value for the AD era. |
1 |
0x00000001 |
int |
BC |
Value for the BC era. |
0 |
0x00000000 |
AM,
AM_PM,
APRIL,
AUGUST,
DATE,
DAY_OF_MONTH,
DAY_OF_WEEK,
DAY_OF_WEEK_IN_MONTH,
DAY_OF_YEAR,
DECEMBER,
DST_OFFSET,
ERA,
FEBRUARY,
FIELD_COUNT,
FRIDAY,
HOUR,
HOUR_OF_DAY,
JANUARY,
JULY,
JUNE,
MARCH,
MAY,
MILLISECOND,
MINUTE,
MONDAY,
MONTH,
NOVEMBER,
OCTOBER,
PM,
SATURDAY,
SECOND,
SEPTEMBER,
SUNDAY,
THURSDAY,
TUESDAY,
UNDECIMBER,
WEDNESDAY,
WEEK_OF_MONTH,
WEEK_OF_YEAR,
YEAR,
ZONE_OFFSET
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. |
Public Constructors
|
|
|
|
|
|
GregorianCalendar() |
|
|
|
|
|
|
GregorianCalendar(int year, int month, int day) |
|
|
|
|
|
|
GregorianCalendar(int year, int month, int day, int hour, int minute) |
|
|
|
|
|
|
GregorianCalendar(int year, int month, int day, int hour, int minute, int second) |
|
|
|
|
|
|
GregorianCalendar(Locale locale) |
|
|
|
|
|
|
GregorianCalendar(TimeZone timezone) |
|
|
|
|
|
|
GregorianCalendar(TimeZone timezone, Locale locale) |
Public Methods
Protected Methods
add,
after,
before,
clear,
clear,
clone,
compareTo,
complete,
computeFields,
computeTime,
equals,
get,
getActualMaximum,
getActualMinimum,
getAvailableLocales,
getFirstDayOfWeek,
getGreatestMinimum,
getInstance,
getInstance,
getInstance,
getInstance,
getLeastMaximum,
getMaximum,
getMinimalDaysInFirstWeek,
getMinimum,
getTime,
getTimeInMillis,
getTimeZone,
hashCode,
internalGet,
isLenient,
isSet,
roll,
roll,
set,
set,
set,
set,
setFirstDayOfWeek,
setLenient,
setMinimalDaysInFirstWeek,
setTime,
setTimeInMillis,
setTimeZone,
toString
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) |
|
|
|
|
|
void |
complete() |
abstract |
|
|
|
|
void |
computeFields() |
abstract |
|
|
|
|
void |
computeTime() |
|
|
|
|
|
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() |
|
|
final |
|
|
int |
internalGet(int field) |
|
|
|
|
|
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() |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
AD
Value for the AD era.
Constant Value:
1
(0x00000001)
public
static
final
int
BC
Value for the BC era.
Constant Value:
0
(0x00000000)
Public Constructors
public
GregorianCalendar()
Constructs a new GregorianCalendar initialized to the current date and
time.
public
GregorianCalendar(int year, int month, int day)
Constructs a new GregorianCalendar initialized to midnight in the default
time zone on the specified date.
Parameters
year
| the year |
month
| the month |
day
| the day of the month
|
public
GregorianCalendar(int year, int month, int day, int hour, int minute)
Constructs a new GregorianCalendar initialized to the specified date and
time.
Parameters
year
| the year |
month
| the month |
day
| the day of the month |
hour
| the hour |
minute
| the minute
|
public
GregorianCalendar(int year, int month, int day, int hour, int minute, int second)
Constructs a new GregorianCalendar initialized to the specified date and
time.
Parameters
year
| the year |
month
| the month |
day
| the day of the month |
hour
| the hour |
minute
| the minute |
second
| the second
|
public
GregorianCalendar(Locale locale)
Constructs a new GregorianCalendar initialized to the current date and
time and using the specified Locale.
public
GregorianCalendar(TimeZone timezone)
Constructs a new GregorianCalendar initialized to the current date and
time and using the specified TimeZone.
public
GregorianCalendar(TimeZone timezone, Locale locale)
Constructs a new GregorianCalendar initialized to the current date and
time and using the specified TimeZone and Locale.
Parameters
timezone
| the TimeZone |
locale
| the Locale
|
Public Methods
public
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
Object
clone()
Creates new instance of GregorianCalendar with the same properties.
Returns
- a shallow copy of this GregorianCalendar
public
boolean
equals(Object object)
Compares the specified object to this GregorianCalendar and answer if
they are equal. The object must be an instance of GregorianCalendar and
have the same properties.
Parameters
object
| the object to compare with this object |
Returns
- true if the specified object is equal to this GregorianCalendar,
false otherwise
public
int
getActualMaximum(int field)
Gets the maximum value of the specified field for the current date. For
example, the maximum number of days in the current month.
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. For
the gregorian calendar, this value is the same as
getMinimum()
.
Returns
- the minimum value of the specified field
public
int
getGreatestMinimum(int field)
Gets the greatest minimum value of the specified field. For the gregorian
calendar, this value is the same as
getMinimum()
.
Returns
- the greatest minimum value of the specified field
public
final
Date
getGregorianChange()
Returns the gregorian change date of this calendar. This is the date on
which the gregorian calendar came into effect.
Returns
- a Date which represents the gregorian change date
public
int
getLeastMaximum(int field)
Gets the smallest maximum value of the specified field. For example, 28
for the day of month field.
Returns
- the smallest maximum value of the specified field
public
int
getMaximum(int field)
Gets the greatest maximum value of the specified field. For example, 31
for the day of month field.
Returns
- the greatest maximum value of the specified field
public
int
getMinimum(int field)
Gets the smallest minimum value of the specified field.
Returns
- the smallest minimum value of the specified field
public
int
hashCode()
Returns an integer hash code for the receiver. Objects which are equal
answer the same value for this method.
public
boolean
isLeapYear(int year)
Returns if the specified year is a leap year.
Returns
- true if the specified year is a leap year, 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
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. For example, March 31 will roll to April 30 when rolling the month
field.
Parameters
field
| the field to roll |
increment
| true to increment the field, false to decrement |
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
setGregorianChange(Date date)
Sets the gregorian change date of this calendar.
Parameters
date
| a Date which represents the gregorian change date
|
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
|
Protected Methods
protected
void
computeFields()
Computes the Calendar fields from the time.
protected
void
computeTime()
Computes the time from the Calendar fields.