Package java.util
Class Calendar
java.lang.Object
java.util.Calendar
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
GregorianCalendar
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intValue of theAM_PMfield indicating the period of the day from midnight to just before noon.static final intField number forgetandsetindicating whether theHOURis before or after noon.static final intValue of theMONTHfield indicating the fourth month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the eighth month of the year in the Gregorian and Julian calendars.static final intField number forgetandsetindicating the day of the month.static final intField number forgetandsetindicating the day of the month.static final intField number forgetandsetindicating the day of the week.static final intField number forgetandsetindicating the ordinal number of the day of the week within the current month.static final intField number forgetandsetindicating the day number within the current year.static final intValue of theMONTHfield indicating the twelfth month of the year in the Gregorian and Julian calendars.static final intField number forgetandsetindicating the era, e.g., AD or BC in the Julian calendar.static final intValue of theMONTHfield indicating the second month of the year in the Gregorian and Julian calendars.static final intValue of theDAY_OF_WEEKfield indicating Friday.static final intField number forgetandsetindicating the hour of the morning or afternoon.static final intField number forgetandsetindicating the hour of the day.static final intValue of theMONTHfield indicating the first month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the seventh month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the sixth month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the third month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the fifth month of the year in the Gregorian and Julian calendars.static final intField number forgetandsetindicating the millisecond within the second.static final intField number forgetandsetindicating the minute within the hour.static final intValue of theDAY_OF_WEEKfield indicating Monday.static final intField number forgetandsetindicating the month.static final intValue of theMONTHfield indicating the eleventh month of the year in the Gregorian and Julian calendars.static final intValue of theMONTHfield indicating the tenth month of the year in the Gregorian and Julian calendars.static final intValue of theAM_PMfield indicating the period of the day from noon to just before midnight.static final intValue of theDAY_OF_WEEKfield indicating Saturday.static final intField number forgetandsetindicating the second within the minute.static final intValue of theMONTHfield indicating the ninth month of the year in the Gregorian and Julian calendars.static final intValue of theDAY_OF_WEEKfield indicating Sunday.static final intValue of theDAY_OF_WEEKfield indicating Thursday.static final intValue of theDAY_OF_WEEKfield indicating Tuesday.static final intValue of theMONTHfield indicating the thirteenth month of the year.static final intValue of theDAY_OF_WEEKfield indicating Wednesday.static final intField number forgetandsetindicating the week number within the current month.static final intField number forgetandsetindicating the week number within the current year.static final intField number forgetandsetindicating the year. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidadd(int field, int value) booleanReturns whether thisCalendarrepresents a time after the time represented by the specifiedObject.booleanReturns whether thisCalendarrepresents a time before the time represented by the specifiedObject.abstract voidclear()abstract Objectclone()intCompares the time values (millisecond offsets from the Epoch) represented by twoCalendarobjects.booleanCompares thisCalendarto the specifiedObject.abstract intget(int field) intgetActualMaximum(int field) intgetActualMinimum(int field) intstatic Calendarintabstract DategetTime()abstract longReturns this Calendar's time value in milliseconds.booleanTells whether date/time interpretation is to be lenient.abstract voidset(int field, int value) Sets the given calendar field to the given value.voidsetFirstDayOfWeek(int newFirstDayOfWeek) voidsetLenient(boolean lenient) Specifies whether or not date/time interpretation is to be lenient.voidsetMinimalDaysInFirstWeek(int newMinimalDaysInFirstWeek) abstract voidSets this Calendar's time with the givenDate.abstract voidsetTimeInMillis(long millis) Sets this Calendar's current time from the given long value.
-
Field Details
-
ERA
public static final int ERAField number forgetandsetindicating the era, e.g., AD or BC in the Julian calendar. This is a calendar-specific value; see subclass documentation. -
YEAR
public static final int YEARField number forgetandsetindicating the year. This is a calendar-specific value; see subclass documentation.- See Also:
-
MONTH
public static final int MONTHField number forgetandsetindicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars isJANUARYwhich is 0; the last depends on the number of months in a year. -
WEEK_OF_YEAR
public static final int WEEK_OF_YEARField number forgetandsetindicating the week number within the current year. The first week of the year, as defined bygetFirstDayOfWeek()andgetMinimalDaysInFirstWeek(), has value 1. Subclasses define the value ofWEEK_OF_YEARfor days before the first week of the year. -
WEEK_OF_MONTH
public static final int WEEK_OF_MONTHField number forgetandsetindicating the week number within the current month. The first week of the month, as defined bygetFirstDayOfWeek()andgetMinimalDaysInFirstWeek(), has value 1. Subclasses define the value ofWEEK_OF_MONTHfor days before the first week of the month. -
DATE
public static final int DATEField number forgetandsetindicating the day of the month. This is a synonym forDAY_OF_MONTH. The first day of the month has value 1.- See Also:
-
DAY_OF_MONTH
public static final int DAY_OF_MONTHField number forgetandsetindicating the day of the month. This is a synonym forDATE. The first day of the month has value 1.- See Also:
-
DAY_OF_YEAR
public static final int DAY_OF_YEARField number forgetandsetindicating the day number within the current year. The first day of the year has value 1.- See Also:
-
DAY_OF_WEEK
public static final int DAY_OF_WEEKField number forgetandsetindicating the day of the week. This field takes valuesSUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY, andSATURDAY. -
DAY_OF_WEEK_IN_MONTH
public static final int DAY_OF_WEEK_IN_MONTHField number forgetandsetindicating the ordinal number of the day of the week within the current month. Together with theDAY_OF_WEEKfield, this uniquely specifies a day within a month. UnlikeWEEK_OF_MONTHandWEEK_OF_YEAR, this field's value does not depend ongetFirstDayOfWeek()orgetMinimalDaysInFirstWeek().DAY_OF_MONTH 1through7always correspond toDAY_OF_WEEK_IN_MONTH 1;8through14correspond toDAY_OF_WEEK_IN_MONTH 2, and so on.DAY_OF_WEEK_IN_MONTH 0indicates the week beforeDAY_OF_WEEK_IN_MONTH 1. Negative values count back from the end of the month, so the last Sunday of a month is specified asDAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1. Because negative values count backward they will usually be aligned differently within the month than positive values. For example, if a month has 31 days,DAY_OF_WEEK_IN_MONTH -1will overlapDAY_OF_WEEK_IN_MONTH 5and the end of4.- See Also:
-
AM_PM
public static final int AM_PMField number forgetandsetindicating whether theHOURis before or after noon. E.g., at 10:04:15.250 PM theAM_PMisPM.- See Also:
-
HOUR
public static final int HOURField number forgetandsetindicating the hour of the morning or afternoon.HOURis used for the 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12. E.g., at 10:04:15.250 PM theHOURis 10.- See Also:
-
HOUR_OF_DAY
public static final int HOUR_OF_DAYField number forgetandsetindicating the hour of the day.HOUR_OF_DAYis used for the 24-hour clock. E.g., at 10:04:15.250 PM theHOUR_OF_DAYis 22.- See Also:
-
MINUTE
public static final int MINUTEField number forgetandsetindicating the minute within the hour. E.g., at 10:04:15.250 PM theMINUTEis 4.- See Also:
-
SECOND
public static final int SECONDField number forgetandsetindicating the second within the minute. E.g., at 10:04:15.250 PM theSECONDis 15.- See Also:
-
MILLISECOND
public static final int MILLISECONDField number forgetandsetindicating the millisecond within the second. E.g., at 10:04:15.250 PM theMILLISECONDis 250.- See Also:
-
SUNDAY
public static final int SUNDAYValue of theDAY_OF_WEEKfield indicating Sunday.- See Also:
-
MONDAY
public static final int MONDAYValue of theDAY_OF_WEEKfield indicating Monday.- See Also:
-
TUESDAY
public static final int TUESDAYValue of theDAY_OF_WEEKfield indicating Tuesday.- See Also:
-
WEDNESDAY
public static final int WEDNESDAYValue of theDAY_OF_WEEKfield indicating Wednesday.- See Also:
-
THURSDAY
public static final int THURSDAYValue of theDAY_OF_WEEKfield indicating Thursday.- See Also:
-
FRIDAY
public static final int FRIDAYValue of theDAY_OF_WEEKfield indicating Friday.- See Also:
-
SATURDAY
public static final int SATURDAYValue of theDAY_OF_WEEKfield indicating Saturday.- See Also:
-
JANUARY
public static final int JANUARYValue of theMONTHfield indicating the first month of the year in the Gregorian and Julian calendars.- See Also:
-
FEBRUARY
public static final int FEBRUARYValue of theMONTHfield indicating the second month of the year in the Gregorian and Julian calendars.- See Also:
-
MARCH
public static final int MARCHValue of theMONTHfield indicating the third month of the year in the Gregorian and Julian calendars.- See Also:
-
APRIL
public static final int APRILValue of theMONTHfield indicating the fourth month of the year in the Gregorian and Julian calendars.- See Also:
-
MAY
public static final int MAYValue of theMONTHfield indicating the fifth month of the year in the Gregorian and Julian calendars.- See Also:
-
JUNE
public static final int JUNEValue of theMONTHfield indicating the sixth month of the year in the Gregorian and Julian calendars.- See Also:
-
JULY
public static final int JULYValue of theMONTHfield indicating the seventh month of the year in the Gregorian and Julian calendars.- See Also:
-
AUGUST
public static final int AUGUSTValue of theMONTHfield indicating the eighth month of the year in the Gregorian and Julian calendars.- See Also:
-
SEPTEMBER
public static final int SEPTEMBERValue of theMONTHfield indicating the ninth month of the year in the Gregorian and Julian calendars.- See Also:
-
OCTOBER
public static final int OCTOBERValue of theMONTHfield indicating the tenth month of the year in the Gregorian and Julian calendars.- See Also:
-
NOVEMBER
public static final int NOVEMBERValue of theMONTHfield indicating the eleventh month of the year in the Gregorian and Julian calendars.- See Also:
-
DECEMBER
public static final int DECEMBERValue of theMONTHfield indicating the twelfth month of the year in the Gregorian and Julian calendars.- See Also:
-
UNDECIMBER
public static final int UNDECIMBERValue of theMONTHfield indicating the thirteenth month of the year. AlthoughGregorianCalendardoes not use this value, lunar calendars do.- See Also:
-
AM
public static final int AMValue of theAM_PMfield indicating the period of the day from midnight to just before noon.- See Also:
-
PM
public static final int PMValue of theAM_PMfield indicating the period of the day from noon to just before midnight.- See Also:
-
-
Constructor Details
-
Calendar
protected Calendar()
-
-
Method Details
-
getTime
- Returns:
- a
Daterepresenting the time value. - See Also:
-
setTime
Sets this Calendar's time with the givenDate.Note: Calling
setTime()withDate(Long.MAX_VALUE)orDate(Long.MIN_VALUE)may yield incorrect field values fromget().- Parameters:
date- the given Date.- See Also:
-
getTimeInMillis
public abstract long getTimeInMillis()Returns this Calendar's time value in milliseconds.- Returns:
- the current time as UTC milliseconds from the epoch.
- See Also:
-
setTimeInMillis
public abstract void setTimeInMillis(long millis) Sets this Calendar's current time from the given long value.- Parameters:
millis- the new time in UTC milliseconds from the epoch.- See Also:
-
get
public abstract int get(int field) -
set
public abstract void set(int field, int value) Sets the given calendar field to the given value. The value is not interpreted by this method regardless of the leniency mode.- Parameters:
field- the given calendar field.value- the value to be set for the given calendar field.- Throws:
ArrayIndexOutOfBoundsException- if the specified field is out of range (field < 0 || field >= FIELD_COUNT). in non-lenient mode.- See Also:
-
add
public abstract void add(int field, int value) -
clear
public abstract void clear() -
getFirstDayOfWeek
public int getFirstDayOfWeek() -
setFirstDayOfWeek
public void setFirstDayOfWeek(int newFirstDayOfWeek) -
getMinimalDaysInFirstWeek
public int getMinimalDaysInFirstWeek() -
setMinimalDaysInFirstWeek
public void setMinimalDaysInFirstWeek(int newMinimalDaysInFirstWeek) -
clone
-
getInstance
-
before
Returns whether thisCalendarrepresents a time before the time represented by the specifiedObject. This method is equivalent to:compareTo(when) < 0if and only ifwhenis aCalendarinstance. Otherwise, the method returnsfalse.- Parameters:
when- theObjectto be compared- Returns:
trueif the time of thisCalendaris before the time represented bywhen;falseotherwise.- See Also:
-
after
Returns whether thisCalendarrepresents a time after the time represented by the specifiedObject. This method is equivalent to:compareTo(when) > 0if and only ifwhenis aCalendarinstance. Otherwise, the method returnsfalse.- Parameters:
when- theObjectto be compared- Returns:
trueif the time of thisCalendaris after the time represented bywhen;falseotherwise.- See Also:
-
equals
Compares thisCalendarto the specifiedObject. The result istrueif and only if the argument is aCalendarobject of the same calendar system that represents the same time value (millisecond offset from the Epoch) under the sameCalendarparameters as this object.The
Calendarparameters are the values represented by theisLenient,getFirstDayOfWeek,getMinimalDaysInFirstWeekandgetTimeZonemethods. If there is any difference in those parameters between the twoCalendars, this method returnsfalse.Use the
compareTomethod to compare only the time values. -
compareTo
Compares the time values (millisecond offsets from the Epoch) represented by twoCalendarobjects.- Parameters:
anotherCalendar- theCalendarto be compared.- Returns:
- the value
0if the time represented by the argument is equal to the time represented by thisCalendar; a value less than0if the time of thisCalendaris before the time represented by the argument; and a value greater than0if the time of thisCalendaris after the time represented by the argument. - Throws:
NullPointerException- if the specifiedCalendarisnull.IllegalArgumentException- if the time value of the specifiedCalendarobject can't be obtained due to any invalid calendar values.- Since:
- 1.5
-
setLenient
public void setLenient(boolean lenient) Specifies whether or not date/time interpretation is to be lenient. With lenient interpretation, a date such as "February 942, 1996" will be treated as being equivalent to the 941st day after February 1, 1996. With strict (non-lenient) interpretation, such dates will cause an exception to be thrown. The default is lenient.- Parameters:
lenient-trueif the lenient mode is to be turned on;falseif it is to be turned off.- See Also:
-
isLenient
public boolean isLenient()Tells whether date/time interpretation is to be lenient.- Returns:
trueif the interpretation mode of this calendar is lenient;falseotherwise.- See Also:
-
getActualMaximum
public int getActualMaximum(int field) -
getActualMinimum
public int getActualMinimum(int field)
-