Android
java.util
public class

java.util.GregorianCalendar

java.lang.Object
java.util.Calendar Serializable Cloneable Comparable<T>
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.  0x00000001 
int  BC  Value for the BC era.  0x00000000 
Constants inherited from class java.util.Calendar
Fields inherited from class java.util.Calendar

Public Constructors

            GregorianCalendar()
Constructs a new GregorianCalendar initialized to the current date and time.
            GregorianCalendar(int year, int month, int day)
Constructs a new GregorianCalendar initialized to midnight in the default time zone on the specified date.
            GregorianCalendar(int year, int month, int day, int hour, int minute)
Constructs a new GregorianCalendar initialized to the specified date and time.
            GregorianCalendar(int year, int month, int day, int hour, int minute, int second)
Constructs a new GregorianCalendar initialized to the specified date and time.
            GregorianCalendar(Locale locale)
Constructs a new GregorianCalendar initialized to the current date and time and using the specified Locale.
            GregorianCalendar(TimeZone timezone)
Constructs a new GregorianCalendar initialized to the current date and time and using the specified TimeZone.
            GregorianCalendar(TimeZone timezone, Locale locale)
Constructs a new GregorianCalendar initialized to the current date and time and using the specified TimeZone and Locale.

Public Methods

          void  add(int field, int value)
Adds the specified amount to a Calendar field.
          Object  clone()
Creates new instance of GregorianCalendar with the same properties.
          boolean  equals(Object object)
Compares the specified object to this GregorianCalendar and answer if they are equal.
          int  getActualMaximum(int field)
Gets the maximum value of the specified field for the current date.
          int  getActualMinimum(int field)
Gets the minimum value of the specified field for the current date.
          int  getGreatestMinimum(int field)
Gets the greatest minimum value of the specified field.
    final      Date  getGregorianChange()
Returns the gregorian change date of this calendar.
          int  getLeastMaximum(int field)
Gets the smallest maximum value of the specified field.
          int  getMaximum(int field)
Gets the greatest maximum value of the specified field.
          int  getMinimum(int field)
Gets the smallest minimum value of the specified field.
          int  hashCode()
Returns an integer hash code for the receiver.
          boolean  isLeapYear(int year)
Returns if the specified year is a leap year.
          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.
          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.
          void  setFirstDayOfWeek(int value)
Sets the first day of the week for this Calendar.
          void  setGregorianChange(Date date)
Sets the gregorian change date of this calendar.
          void  setMinimalDaysInFirstWeek(int value)
Sets the minimal days in the first week of the year.

Protected Methods

          void  computeFields()
Computes the Calendar fields from the time.
          void  computeTime()
Computes the time from the Calendar fields.
Methods inherited from class java.util.Calendar
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.Comparable

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.

Parameters

locale the Locale

public GregorianCalendar(TimeZone timezone)

Constructs a new GregorianCalendar initialized to the current date and time and using the specified TimeZone.

Parameters

timezone the 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

Throws

IllegalArgumentException when the specified field is DST_OFFSET or ZONE_OFFSET.

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

Throws

IllegalArgumentException when the time is not set and the time cannot be computed from the current field values

See Also

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.

Parameters

field the field

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().

Parameters

field the field

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().

Parameters

field the field

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.

Parameters

field the 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.

Parameters

field the field

Returns

  • the greatest maximum value of the specified field

public int getMinimum(int field)

Gets the smallest minimum value of the specified field.

Parameters

field the 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.

Returns

  • the receiver's hash

See Also

public boolean isLeapYear(int year)

Returns if the specified year is a leap year.

Parameters

year the 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

Throws

IllegalArgumentException when an invalid field is specified

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

Throws

IllegalArgumentException when an invalid field is specified

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.

Throws

IllegalArgumentException when the time cannot be computed from the current field values
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56