Calendar class

The calendar field values can be set by calling the set methods.

Constants for AM/PM

TypeFieldSummary
static intAMIndicating the period of the day from midnight to just before noon.
static intAM_PMField number for get and set indicating whether the HOUR is before or after noon.
static intPMIndicating the period of the day from noon to just before midnight.

Constants for Date

TypeFieldSummary
static intDAY_OF_MONTHFor get and set indicating the day of the month.
static intDAY_OF_WEEKFor get and set indicating the day of the week.
static intDAY_OF_WEEK_IN_MONTHFor get and set indicating the ordinal number of the day of the week within the current month.
static intDAY_OF_YEARFor get and set indicating the day number within the current year.
static intHOURFor get and set indicating the hour of the morning or afternoon.
static intHOUR_OF_DAYFor get and set indicating the hour of the day.
static intDATEFor get and set indicating the day of the month.
static intERAFor get and set indicating the era, e.g., AD or BC in the Julian calendar.
static intMILLISECONDFor get and set indicating the millisecond within the second.
static intMINUTEFor get and set indicating the minute within the hour.
static intMONTHFor get and set indicating the month.
static intSECONDFor get and set indicating the second within the minute.
static intWEEK_OF_MONTHFor get and set indicating the week number within the current month.
static intWEEK_OF_YEARFor get and set indicating the week number within the current year.
static intYEARFor get and set indicating the year.

Constants for Month

TypeFieldSummary
static intJANUARYfirst month
static intFEBRUARYsecond month
static intMARCHthird month
static intAPRILfourth month
static intMAYfifth month
static intJUNEsixth month
static intJULYseventh month
static intAUGUSTeighth month
static intSEPTEMBERninth month
static intOCTOBERtenth month
static intNOVEMBEReleventh month
static intDECEMBERtwelfth month
static intUNDECIMBERValue of the MONTH field indicating the thirteenth month of the year.

Constants for WeekDay

TypeFieldSummary
static intMONDAYMonday.
static intTUESDAYTuesday.
static intWEDNESDAYWednesday.
static intTHURSDAYThursday.
static intFRIDAYFriday.
static intSATURDAYSaturday.
static intSUNDAYSunday.

Constants for display name format

TypeFieldSummary
static intLONGFor getDisplayName and getDisplayNames indicating a long name, such as "January".
static intSHORTFor getDisplayName and getDisplayNames indicating a short name, such as "Jan".
static intALL_STYLESFor getDisplayNames indicating names in all styles, such as "January" and "Jan".

Constants for Timezone

TypeFieldSummary
static intDST_OFFSETField number for get and set indicating the daylight savings offset in milliseconds.
static intFIELD_COUNTThe number of distinct fields recognized by get and set.
static intZONE_OFFSETField number for get and set indicating the raw offset from GMT in milliseconds.

Create new Calendar instance

ReturnMethodSummary
static CalendargetInstance()Gets a calendar using the default time zone and locale.
static CalendargetInstance(Locale aLocale)Gets a calendar using the default time zone and specified locale.
static CalendargetInstance(TimeZone zone)Gets a calendar using the specified time zone and default locale.
static CalendargetInstance(TimeZone zone, Locale aLocale)Gets a calendar with the specified time zone and locale.

Get field value from Calendar

TypeMethodSummary
intget(int field)Returns the value of the given calendar field.
intgetActualMaximum(int field)Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.
intgetActualMinimum(int field)Returns the minimum value that the specified calendar field could have, given the time value of this Calendar.
intgetFirstDayOfWeek()Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
intgetMinimalDaysInFirstWeek()Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1.
DategetTime()Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").
longgetTimeInMillis()Returns this Calendar's time value in milliseconds.
TimeZonegetTimeZone()Gets the time zone.

Clear a field or all fields

TypeMethodSummary
voidclear()Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.
voidclear(int field)Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Compare to Calendar

TypeMethodSummary
booleanafter(Object when)Returns whether this Calendar represents a time after the time represented by the specified Object.
booleanbefore(Object when)Returns whether this Calendar represents a time before the time represented by the specified Object.
intcompareTo(Calendar anotherCalendar)Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.
booleanequals(Object obj)Compares this Calendar to the specified Object.

Calendar and display name

TypeMetodSummary
static Locale[]getAvailableLocales()Returns an array of all locales for which the getInstance methods of this class can return localized instances.
StringgetDisplayName(int field, int style, Locale locale)Returns the string representation of the calendar field value in the given style and locale.
Map<String,Integer>getDisplayNames(int field, int style, Locale locale)Returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values.

Is lenient

TypeMethodSummary
booleanisLenient()Tells whether date/time interpretation is to be lenient.

Add/set value to a field and get new calendar value

TypeMethodSummary
voidadd(int field, int amount)Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.
voidroll(int field, int amount)Adds the specified (signed) amount to the specified calendar field without changing larger fields.
voidset(int field, int value)Sets the given calendar field to the given value.
voidset(int year, int month, int date)Sets the values for the calendar fields YEAR, MONTH, and DAY_OF_MONTH.
voidset(int year, int month, int date, int hourOfDay, int minute)Sets the values for the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, and MINUTE.
voidset(int year, int month, int date, int hourOfDay, int minute, int second)Sets the values for the fields YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, and SECOND.
voidsetFirstDayOfWeek(int value)Sets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.
voidsetLenient(boolean lenient)Specifies whether or not date/time interpretation is to be lenient.
voidsetMinimalDaysInFirstWeek(int value)Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call this method with value 1.
voidsetTime(Date date)Sets this Calendar's time with the given Date.
voidsetTimeInMillis(long millis)Sets this Calendar's current time from the given long value.
voidsetTimeZone(TimeZone value)Sets the time zone with the given time zone value.
booleanisSet(int field)Determines if the given calendar field has a value set, including cases that the value has been set by internal fields calculations triggered by a get method call.

Convert Calendar value to string value

TypeMethodSummary
StringtoString()Return a string representation of this calendar.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.