Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util

Class GregorianCalendar

java.lang.Object
|
+--java.util.Calendar
   |
   +--java.util.GregorianCalendar


public class GregorianCalendar

extends Calendar

This class represents the Gregorian calendar, that is used in most countries all over the world. It does also handle the Julian calendar for dates smaller than the date of the change to the Gregorian calendar. This change date is different from country to country, you can set it with setGregorianChange The Gregorian calendar differs from the Julian calendar by a different leap year rule (no leap year every 100 years, except if year is divisible by 400). The non existing days that were omited when the change took place are interpreted as gregorian date There are to eras available for the Gregorian calendar, namely BC and AD.

See Also:

Field Summary

static intAD

Constant representing the era AD (Anno Domini).
static intBC

Constant representing the era BC (before Christ).

Constructor Summary

GregorianCalendar()

Constructs a new GregorianCalender representing the current time, using the default time zone and the default locale.
GregorianCalendar(java.util.TimeZone zone)

Constructs a new GregorianCalender representing the current time, using the specified time zone and the default locale.
GregorianCalendar(java.util.Locale locale)

Constructs a new GregorianCalender representing the current time, using the default time zone and the specified locale.
GregorianCalendar(java.util.TimeZone zone, java.util.Locale locale)

Constructs a new GregorianCalender representing the current time with the given time zone and the given locale.
GregorianCalendar(int year, int month, int day)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.
GregorianCalendar(int year, int month, int day, int hour, int minute)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.
GregorianCalendar(int year, int month, int day, int hour, int minute, int second)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.

Method Summary

voidadd(int field, int amount)

Adds the specified amount of time to the given time field.
synchronized voidcomputeFields()

Converts the milliseconds since the epoch UTC (time) to time fields (fields).
synchronized voidcomputeTime()

Converts the time field values (fields) to milliseconds since the epoch UTC (time).
booleanequals(java.lang.Object o)

Compares the given calender with this.
intgetActualMaximum(int field)

Gets the actual maximum value that is allowed for the specified field.
intgetActualMinimum(int field)

Gets the actual minimum value that is allowed for the specified field.
intgetGreatestMinimum(int field)

Gets the greatest minimum value that is allowed for the specified field.
java.util.DategetGregorianChange()

Gets the date of the switch from Julian dates to Gregorian dates.
intgetLeastMaximum(int field)

Gets the smallest maximum value that is allowed for the specified field.
intgetMaximum(int field)

Gets the biggest value that is allowed for the specified field.
intgetMinimum(int field)

Gets the smallest value that is allowed for the specified field.
booleanisLeapYear(int year)

Determines if the given year is a leap year.
voidroll(int field, boolean up)

Rolls the specified time field up or down.
voidroll(int field, int amount)

Rolls the specified time field by the given amount.
voidsetGregorianChange(java.util.Date date)

Sets the date of the switch from Julian dates to Gregorian dates.

Field Details

AD

public static final int AD

Constant representing the era AD (Anno Domini).


BC

public static final int BC

Constant representing the era BC (before Christ).


Constructor Details

GregorianCalendar

public GregorianCalendar()

Constructs a new GregorianCalender representing the current time, using the default time zone and the default locale.


GregorianCalendar

public GregorianCalendar(int year, int month, int day)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.

Parameters:


GregorianCalendar

public GregorianCalendar(int year, int month, int day, int hour, int minute)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.

Parameters:


GregorianCalendar

public GregorianCalendar(int year, int month, int day, int hour, int minute, int second)

Constructs a new GregorianCalendar representing midnight on the given date with the default time zone and locale.

Parameters:


GregorianCalendar

public GregorianCalendar(java.util.Locale locale)

Constructs a new GregorianCalender representing the current time, using the default time zone and the specified locale.

Parameters:


GregorianCalendar

public GregorianCalendar(java.util.TimeZone zone)

Constructs a new GregorianCalender representing the current time, using the specified time zone and the default locale.

Parameters:


GregorianCalendar

public GregorianCalendar(java.util.TimeZone zone, java.util.Locale locale)

Constructs a new GregorianCalender representing the current time with the given time zone and the given locale.

Parameters:


Method Details

add

public 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:


computeFields

protected synchronized void computeFields()

Converts the milliseconds since the epoch UTC (time) to time fields (fields).


computeTime

protected synchronized void computeTime()

Converts the time field values (fields) to milliseconds since the epoch UTC (time).


equals

public boolean equals(java.lang.Object o)

Compares the given calender with this.

Parameters:

Returns:


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. Note that this calls complete() if not enough fields are set. This can have ugly side effects.

Parameters:

Returns:


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. Note that this calls complete() if not enough fields are set. This can have ugly side effects.

Since:Parameters:

Returns:


getGreatestMinimum

public int getGreatestMinimum(int field)

Gets the greatest minimum value that is allowed for the specified field.

Parameters:

Returns:


getGregorianChange

public final Date getGregorianChange()

Gets the date of the switch from Julian dates to Gregorian dates.

Returns:


getLeastMaximum

public 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.

Since:Parameters:

Returns:


getMaximum

public int getMaximum(int field)

Gets the biggest value that is allowed for the specified field.

Parameters:

Returns:


getMinimum

public int getMinimum(int field)

Gets the smallest value that is allowed for the specified field.

Parameters:

Returns:


isLeapYear

public boolean isLeapYear(int year)

Determines if the given year is a leap year. The result is undefined if the gregorian change took place in 1800, so that the end of february is skiped and you give that year (well...).
The year should be positive and you can't give an ERA. But remember that before 4 BC there wasn't a consistent leap year rule, so who cares.

Parameters:

Returns:


roll

public 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. This requires lenient settings.

Parameters:


roll

public void roll(int field, int amount)

Rolls the specified time field by the given amount. This means add amount 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 and vice versa for negative amounts. 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 corrected to June, 30.

Parameters:


setGregorianChange

public void setGregorianChange(java.util.Date date)

Sets the date of the switch from Julian dates to Gregorian dates. You can use new Date(Long.MAX_VALUE) to use a pure Julian calendar, or Long.MIN_VALUE for a pure Gregorian calendar.

Parameters: