DthingApi
|
Public Member Functions | |
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) | |
void | add (int field, int value) |
Object | clone () |
boolean | equals (Object object) |
int | getActualMaximum (int field) |
int | getActualMinimum (int field) |
int | getGreatestMinimum (int field) |
final Date | getGregorianChange () |
int | getLeastMaximum (int field) |
int | getMaximum (int field) |
int | getMinimum (int field) |
int | hashCode () |
boolean | isLeapYear (int year) |
void | roll (int field, int value) |
void | roll (int field, boolean increment) |
void | setGregorianChange (Date date) |
void | setFirstDayOfWeek (int value) |
void | setMinimalDaysInFirstWeek (int value) |
![]() | |
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 Attributes | |
static final int | BC = 0 |
static final int | AD = 1 |
![]() | |
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 | |
void | computeFields () |
void | computeTime () |
![]() | |
Calendar () | |
Calendar (TimeZone timezone, Locale locale) | |
void | complete () |
abstract void | computeFields () |
abstract void | computeTime () |
final int | internalGet (int field) |
Additional Inherited Members | |
![]() | |
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) |
![]() | |
boolean | areFieldsSet |
int [] | fields |
boolean [] | isSet |
boolean | isTimeSet |
long | time |
is a concrete subclass of Calendar and provides the standard calendar used by most of the world.
The standard (Gregorian) calendar has 2 eras, BC and AD.
This implementation handles a single discontinuity, which corresponds by default to the date the Gregorian calendar was instituted (October 15, 1582 in some countries, later in others). The cutover date may be changed by the caller by calling
.
Historically, in those countries which adopted the Gregorian calendar first, October 4, 1582 was thus followed by October 15, 1582. This calendar models this correctly. Before the Gregorian cutover,
implements the Julian calendar. The only difference between the Gregorian and the Julian calendar is the leap year rule. The Julian calendar specifies leap years every four years, whereas the Gregorian calendar omits century years which are not divisible by 400.
implements proleptic Gregorian and Julian calendars. That is, dates are computed by extrapolating the current rules indefinitely far backward and forward in time. As a result,
may be used for all years to generate meaningful and consistent results. However, dates obtained using
are historically accurate only from March 1, 4 AD onward, when modern Julian calendar rules were adopted. Before this date, leap year rules were applied irregularly, and before 45 BC the Julian calendar did not even exist.
Prior to the institution of the Gregorian calendar, New Year's Day was March
Values calculated for the
field range from 1 to
For example, January 1, 1998 was a Thursday. If
is
and
is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. If, however,
is
, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997.
Values calculated for the
field range from 0 or 1 to 4 or 5. Week 1 of a month (the days with WEEK_OF_MONTH = 1
) is the earliest set of at least
contiguous days in that month, ending on the day before
. Unlike week 1 of a year, week 1 of a month may be shorter than 7 days, need not start on
, and will not include days of the previous month. Days of a month before week 1 have a
of 0.
For example, if
is
and
is 4, then the first week of January 1998 is Sunday, January 4 through Saturday, January 10. These days have a
of 1. Thursday, January 1 through Saturday, January 3 have a
of 0. If
is changed to 3, then January 1 through January 3 have a
of 1.
Example:
// get the supported ids for GMT-08:00 (Pacific Standard Time) String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); // if no ids were returned, something is wrong. get out. if (ids.length == 0) System.exit(0);// begin output System.out.println("Current Time");// create a Pacific Standard Time time zone SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);// set up rules for daylight savings time pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);// create a GregorianCalendar with the Pacific Daylight time zone // and the current date and time Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);// print out a bunch of interesting things System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000)));System.out.println("Current Time, with hour reset to 3"); calendar.clear(Calendar.HOUR_OF_DAY); // so doesn't override calendar.set(Calendar.HOUR, 3); System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000))); // in hours System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET)/(60*60*1000))); // in hours
|
inline |
Constructs a new
initialized to the current date and time with the default
and
.
|
inline |
Constructs a new
initialized to midnight in the default
and
on the specified date.
year | the year. |
month | the month. |
day | the day of the month. |
|
inline |
Constructs a new
initialized to the specified date and time in the default
and
.
year | the year. |
month | the month. |
day | the day of the month. |
hour | the hour. |
minute | the minute. |
|
inline |
Constructs a new
initialized to the specified date and time in the default
and
.
year | the year. |
month | the month. |
day | the day of the month. |
hour | the hour. |
minute | the minute. |
second | the second. |
|
inline |
Constructs a new
initialized to the current date and time and using the specified
and the default
.
locale | the Locale |
|
inline |
Constructs a new
initialized to the current date and time and using the specified
and the default
.
timezone | the TimeZone |
Constructs a new
initialized to the current date and time and using the specified
and
.
timezone | the TimeZone |
locale | the Locale |
|
inline |
|
inline |
Creates new instance of
with the same properties.
|
inline |
Compares the specified
to this
and returns whether they are equal. To be equal, the
must be an instance of
and have the same properties.
object | the Object |
IllegalArgumentException | if the time is not set and the time cannot be computed from the current field values. |
|
inline |
Gets the maximum value of the specified field for the current date. For example, the maximum number of days in the current month.
field | the field. |
|
inline |
Gets the minimum value of the specified field for the current date. For the gregorian calendar, this value is the same as
.
field | the field. |
|
inline |
Gets the greatest minimum value of the specified field. For the gregorian calendar, this value is the same as
.
field | the field. |
|
inline |
Returns the gregorian change date of this calendar. This is the date on which the gregorian calendar came into effect.
|
inline |
Gets the smallest maximum value of the specified field. For example, 28 for the day of month field.
field | the field. |
|
inline |
Gets the greatest maximum value of the specified field. For example, 31 for the day of month field.
field | the field. |
|
inline |
Gets the smallest minimum value of the specified field.
field | the field. |
|
inline |
Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.
|
inline |
Returns whether the specified year is a leap year.
year | the year. |
|
inline |
Adds the specified amount 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. |
IllegalArgumentException | if an invalid field is specified. |
|
inline |
Increments or decrements 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. For example, March 31 will roll to April 30 when rolling the month field.
field | the field to roll. |
increment | true false |
IllegalArgumentException | if an invalid field is specified. |
|
inline |
Sets the gregorian change date of this calendar.
date | a Date |
|
static |
Value for the AD era.
|
static |
Value for the BC era.