DthingApi
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
java.util.GregorianCalendar Class Reference
Inheritance diagram for java.util.GregorianCalendar:
java.util.Calendar java.io.Serializable

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)
 
- Public Member Functions inherited from java.util.Calendar
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 Public Attributes inherited from java.util.Calendar
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 ()
 
- Protected Member Functions inherited from java.util.Calendar
 Calendar ()
 
 Calendar (TimeZone timezone, Locale locale)
 
void complete ()
 
abstract void computeFields ()
 
abstract void computeTime ()
 
final int internalGet (int field)
 

Additional Inherited Members

- Static Public Member Functions inherited from java.util.Calendar
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)
 
- Protected Attributes inherited from java.util.Calendar
boolean areFieldsSet
 
int [] fields
 
boolean [] isSet
 
boolean isTimeSet
 
long time
 

Detailed Description

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

  1. To avoid confusion, this calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.

Values calculated for the

field range from 1 to

  1. Week 1 for a year is the earliest seven day period starting on that contains at least days from that year. It thus depends on the values of , , and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).

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

See also
Calendar
TimeZone

Constructor & Destructor Documentation

◆ GregorianCalendar() [1/7]

java.util.GregorianCalendar.GregorianCalendar ( )
inline

Constructs a new

initialized to the current date and time with the default

Locale

and

TimeZone

.

◆ GregorianCalendar() [2/7]

java.util.GregorianCalendar.GregorianCalendar ( int  year,
int  month,
int  day 
)
inline

Constructs a new

initialized to midnight in the default

TimeZone

and

Locale

on the specified date.

Parameters
yearthe year.
monththe month.
daythe day of the month.

◆ GregorianCalendar() [3/7]

java.util.GregorianCalendar.GregorianCalendar ( int  year,
int  month,
int  day,
int  hour,
int  minute 
)
inline

Constructs a new

initialized to the specified date and time in the default

TimeZone

and

Locale

.

Parameters
yearthe year.
monththe month.
daythe day of the month.
hourthe hour.
minutethe minute.

◆ GregorianCalendar() [4/7]

java.util.GregorianCalendar.GregorianCalendar ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second 
)
inline

Constructs a new

initialized to the specified date and time in the default

TimeZone

and

Locale

.

Parameters
yearthe year.
monththe month.
daythe day of the month.
hourthe hour.
minutethe minute.
secondthe second.

◆ GregorianCalendar() [5/7]

java.util.GregorianCalendar.GregorianCalendar ( Locale  locale)
inline

Constructs a new

initialized to the current date and time and using the specified

Locale

and the default

TimeZone

.

Parameters
localethe
Locale
.

◆ GregorianCalendar() [6/7]

java.util.GregorianCalendar.GregorianCalendar ( TimeZone  timezone)
inline

Constructs a new

initialized to the current date and time and using the specified

TimeZone

and the default

Locale

.

Parameters
timezonethe
TimeZone
.

◆ GregorianCalendar() [7/7]

java.util.GregorianCalendar.GregorianCalendar ( TimeZone  timezone,
Locale  locale 
)
inline

Constructs a new

initialized to the current date and time and using the specified

TimeZone

and

Locale

.

Parameters
timezonethe
TimeZone
.
localethe
Locale
.

Member Function Documentation

◆ add()

void java.util.GregorianCalendar.add ( int  field,
int  value 
)
inline

Adds the specified amount to a

field.

Parameters
fieldthe field to modify.
valuethe amount to add to the field.
Exceptions
IllegalArgumentExceptionif the specified field is DST_OFFSET or ZONE_OFFSET.

◆ clone()

Object java.util.GregorianCalendar.clone ( )
inline

Creates new instance of

with the same properties.

Returns
a shallow copy of this .

◆ equals()

boolean java.util.GregorianCalendar.equals ( Object  object)
inline

Compares the specified

Object

to this

and returns whether they are equal. To be equal, the

Object

must be an instance of

and have the same properties.

Parameters
objectthe
Object
to compare with this .
Returns
true
if
object
is equal to this ,
false
otherwise.
Exceptions
IllegalArgumentExceptionif the time is not set and the time cannot be computed from the current field values.
See also
hashCode

◆ getActualMaximum()

int java.util.GregorianCalendar.getActualMaximum ( int  field)
inline

Gets the maximum value of the specified field for the current date. For example, the maximum number of days in the current month.

Parameters
fieldthe field.
Returns
the maximum value of the specified field.

◆ getActualMinimum()

int java.util.GregorianCalendar.getActualMinimum ( int  field)
inline

Gets the minimum value of the specified field for the current date. For the gregorian calendar, this value is the same as

.

Parameters
fieldthe field.
Returns
the minimum value of the specified field.

◆ getGreatestMinimum()

int java.util.GregorianCalendar.getGreatestMinimum ( int  field)
inline

Gets the greatest minimum value of the specified field. For the gregorian calendar, this value is the same as

.

Parameters
fieldthe field.
Returns
the greatest minimum value of the specified field.

◆ getGregorianChange()

final Date java.util.GregorianCalendar.getGregorianChange ( )
inline

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.

◆ getLeastMaximum()

int java.util.GregorianCalendar.getLeastMaximum ( int  field)
inline

Gets the smallest maximum value of the specified field. For example, 28 for the day of month field.

Parameters
fieldthe field.
Returns
the smallest maximum value of the specified field.

◆ getMaximum()

int java.util.GregorianCalendar.getMaximum ( int  field)
inline

Gets the greatest maximum value of the specified field. For example, 31 for the day of month field.

Parameters
fieldthe field.
Returns
the greatest maximum value of the specified field.

◆ getMinimum()

int java.util.GregorianCalendar.getMinimum ( int  field)
inline

Gets the smallest minimum value of the specified field.

Parameters
fieldthe field.
Returns
the smallest minimum value of the specified field.

◆ hashCode()

int java.util.GregorianCalendar.hashCode ( )
inline

Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.

Returns
the receiver's hash.
See also
equals

◆ isLeapYear()

boolean java.util.GregorianCalendar.isLeapYear ( int  year)
inline

Returns whether the specified year is a leap year.

Parameters
yearthe year.
Returns
true
if the specified year is a leap year,
false
otherwise.

◆ roll() [1/2]

void java.util.GregorianCalendar.roll ( int  field,
int  value 
)
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.

Parameters
fieldthe field to roll.
valuethe amount to add.
Exceptions
IllegalArgumentExceptionif an invalid field is specified.

◆ roll() [2/2]

void java.util.GregorianCalendar.roll ( int  field,
boolean  increment 
)
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.

Parameters
fieldthe field to roll.
increment
true
to increment the field,
false
to decrement.
Exceptions
IllegalArgumentExceptionif an invalid field is specified.

◆ setGregorianChange()

void java.util.GregorianCalendar.setGregorianChange ( Date  date)
inline

Sets the gregorian change date of this calendar.

Parameters
datea
Date
which represents the gregorian change date.

Member Data Documentation

◆ AD

final int java.util.GregorianCalendar.AD = 1
static

Value for the AD era.

◆ BC

final int java.util.GregorianCalendar.BC = 0
static

Value for the BC era.


The documentation for this class was generated from the following file: