- java.lang.Object
-
- java.util.Calendar
-
- All implemented interfaces
-
Serializable,Cloneable,Comparable<Calendar>
- Known Direct Subclasses:
-
GregorianCalendar
public abstract class Calendar extends Object implements Serializable, Cloneable, Comparable<Calendar>
AforementionedCalendarThe class is an abstract class that can provide methods for conversion between a specific instant and a set.calendar fieldsFor exampleYEAR,MONTH,DAY_OF_MONTH,HOUR, etc., and used to manipulate the calendar fields, such as obtaining the next week of a date. 瞬betweenCan be used毫secondValueRepresents, thisValueYes1970year1month1day格林威ConquerStandardTime1970year1month1day00:00:00,000(格里High利) ofEpochthe offset.This class also provides additional fields and methods for implementing concrete calendar systems outside the package. These fields and methods are defined as
protected。Like other locale-sensitive classes,
CalendarProvides a class methodgetInstance, for getting a generally useful object of this type.CalendarofgetInstancemethod returns aCalendarAn object whose calendar fields have been initialized with the current date and time:Calendar rightNow = Calendar.getInstance();CalendarThe object can generate all calendar field values needed to implement date-time formatting for a particular language and calendar style (for example, Japanese - Gregorian, Japanese - Traditional).CalendarDefines the value ranges returned by certain calendar fields and their meanings. For example, the value of the first month of the calendar system for all calendars isMONTH == JANUARY。 Other values are defined by concrete subclasses, e.g.ERA。 For more information, please refer to the documentation for each field and the subclass documentation.Getting and Setting Calendar Field Values
can be obtained by calling
setMethod to set the calendar field value.CalendarAny field value that is set will not be interpreted until its time value (milliseconds from Epoch) or calendar field value needs to be calculated. Callget,getTimeInMillis,getTime,addandrollInvolves such computation.Lenient
CalendarHas explanation of calendar fields,Loose , Stricttwo modes. WhenCalendarIn lenient mode, it accepts a wider range of calendar field values than it produces. WhenCalendarrecompute and returnCalendarWhen the calendar field value,get()All calendar fields are normalized. For example, lenientGregorianCalendarExplanationMONTH == JANUARY,DAY_OF_MONTH == 32such as February 1.When
CalendarWhen in non-lenient mode, if there is any inconsistency in its calendar fields, an exception is thrown. For example,GregorianCalendarAlways generates a value between 1 and the length of the monthDAY_OF_MONTHvalue. If any field value has been set out of range, then non-lenientGregorianCalendarThrows an exception when calculating its time or calendar field values.First Week
CalendarDefines a locale-specific seven-day work week using two parameters: the first day of the week and the minimum number of days in the first week (from 1 to 7). When constructingCalendarWhen, these numbers are taken from the locale resource data or the locale itself. If the specified locale contains 'fw' and/or 'rg'Unicode extensions, then the first day of the week is obtained according to these extensions. If both 'fw' and 'rg' are specified, the values in the 'fw' extension will override the implied values in the 'rg' extension. They can also be explicitly specified by methods that set their values.Sets or gets
WEEK_OF_MONTHorWEEK_OF_YEARwhen the field,CalendarThe first week of a month or year must be determined as the reference point. The first week of a month or year is defined as starting fromgetFirstDayOfWeek()Starts with and contains at least the month or yeargetMinimalDaysInFirstWeek()The earliest seven-day period of the day. Week numbers before the first week are numbered as......, -1,0; The week numbers are 2, 3, ... following it. Please note,get()The returned normalized number may be different. For example, a specificCalendarSubclasses can specify the week before the first week of a year as the previous year'snWeek.Calendar field resolution
fromCalendarFieldsComputedayperiodandTimewhen,possibleno足够ofInformationused forCompute(For exampleOnlyyearmonthandmonth份nodayperiod), orpossibleExistsNoconsistentofInformation(For example1996year7month15day星period二(格里High利) ) - 1996year7month15dayreal际TopYes星periodone)。CalendarThe calendar field values will be parsed to determine the date and time as follows.If there is any conflict in calendar field values,
Calendargives priorities to calendar fields that have been set more recently.The following are the default combinations of calendar fields. The latest combination determined by the most recently set single field will be used.
For the time of day fields :YEAR + MONTH + DAY_OF_MONTH YEAR + MONTH + WEEK_OF_MONTH + DAY_OF_WEEK YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK YEAR + DAY_OF_YEAR YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
HOUR_OF_DAY AM_PM + HOUR
If any calendar field value is not set in the selected field combination, then
CalendarWill use its default value. The default value of each field may vary depending on the specific calendar system. For example, inGregorianCalendar, the default value of a field is the beginning of the same era: that is,YEAR = 1970,MONTH = JANUARY,DAY_OF_MONTH = 1, etc.Note:There are some possible ambiguities in the interpretation of certain singular times, which can be resolved by the following means:
- 23:59 is the last minute of the day, and 00:00 is the first minute of the next day. Therefore, 23:59 on December 31, 1999 < 00:00 on January 1, 2000 < 00:01 on January 1, 2000.
- Although历史TopNo准confirm,午夜alsoAttributein“Top午”,Medium午Attributein“Bottom午”, so insameone天,凌晨12:00(午夜)<12:01 am,Medium午12:00(Medium午)<12 :01 pm
Date or time format strings are not part of the calendar definition, because users must be able to modify or override these strings at runtime. Usage
DateFormatformatted date.Wild manipulation
: The calendar fields can be changed in three waysset(),add()androll()。set(f, value)Change calendar fieldsfTovalue。 In addition, it sets internal member variables to indicate calendar fields.fChanged. Although calendar fieldsfImmediately after a change, the calendar's time value in milliseconds is not recalculated until the next callget(),getTime(),getTimeInMillis(),add(), orroll()formed. Therefore, forset()Multiple calls will not trigger multiple unnecessary computations. as usedset()As a result of changing a calendar field, other calendar fields may also change, depending on the calendar field, the calendar field value, and the calendar system. In addition,get(f)does not necessarily returnvalueSet to via telephonesetAfter the method's calendar fields have been recalculated. The specific meaning is determined by the concrete calendar class.For example: consider
GregorianCalendarInitially set to 1999, called August 31,set(Calendar.MONTH, Calendar.SEPTEMBER)Set date to September 31, 1999, this is a temporary internal representation parsed as October 1, 1999, ifgetTime(), then call. However, when callingset(Calendar.DAY_OF_MONTH, 30)called beforegetTime()Set the date to September 30, 1999, because inset()Not recalculated afterwards.add(f, delta)IncreasedeltaOn sitef。 This is equivalent to calling adjust twice.set(f, get(f) + delta):Add rule 1. The value of field
fafter the call minus the value of fieldfbefore the call isdelta, modulo any overflow that has occurred in fieldf. Overflow occurs when a field value exceeds its range and, as a result, the next larger field is incremented or decremented and the field value is adjusted back into its range.Add rule 2. If a smaller field is expected to be invariant, but it is impossible for it to be equal to its prior value because of changes in its minimum or maximum after field
fis changed or other constraints, such as time zone offset changes, then its value is adjusted to be as close as possible to its expected value. A smaller field represents a smaller unit of time.HOURis a smaller field thanDAY_OF_MONTH. No adjustment is made to smaller fields that are not expected to be invariant. The calendar system determines what fields are expected to be invariant.In addition, with
set()Different,add()Force an immediate recalculation of the calendar's millisecond value and all fields.For example: consider
GregorianCalendarInitially set to 1999, called August 31,add(Calendar.MONTH, 13)Set the calendar to September 30, 2000.Add rule 1setMONTHField to September, because adding 13 months to the month gives next year's September. Due toDAY_OF_MONTHcannot be in SeptemberGregorianCalendar, thereforeAdd rule 2willDAY_OF_MONTHSet to the nearest possible value. Although it is a smaller field,DAY_OF_WEEKRule 2 does not apply toDAY_OF_WEEKAn adjustment is made because when the month is inGregorianCalendarWhen a change occurs, it is expected to change.roll(f, delta)IncreasedeltaOn sitefDoes not change larger fields. This is equivalent to calling with the following adjustmentsadd(f, delta):Roll rule. Larger fields are unchanged after the call. A larger field represents a larger unit of time.
DAY_OF_MONTHis a larger field thanHOUR.Example: see
GregorianCalendar.roll(int, int)。usage pattern 。 To trigger
add()androll()For the behavior, consider the increment and decrement buttons for month, day, and year, and the underlyingGregorianCalendaruser interface components. If the interface reads January 31, 1999 and the user presses the month increment button, what should it read? If the underlying implementation usesset(), itpossiblewillreadto1999year3month3day。更OKofResultwill be1999year2month28day. In addition, ifuseragainpressmonthinsertquantitybutton,itshouldYes1999year3month31day, rather than1999year3month28day。ThroughSaveoriginaldayperiodandUsageadd()orroll()Depending on whether it should affect larger fields, the user interface can behave as most users intuitively expect.- Starting from the following version:
- 1.1
- See also:
-
System.currentTimeMillis(),Date,GregorianCalendar,TimeZone,DateFormat, Serialized Form
-
-
Nested Class Summary
Nested class Variables and types Class Description static classCalendar.BuilderCalendar.BuilderUsed to create from various date-time parameters.Calendar。
-
Field Summary
Fields Variables and types Fields Description static intALL_STYLESgetDisplayNamesstyle specifiers that indicate the names in all styles, e.g., 'January' and 'Jan'.static intAMAM_PMThe value of the field, representing the period of the day from midnight to just before noon.static intAM_PMgetandsetfield number representingHOURis before or after noon.static intAPRILMONTHThe field value indicating the fourth month of the year in the Gregorian and Julian calendars.protected booleanareFieldsSetiffields[]Synchronized with the currently set time,fields[]True。static intAUGUSTMONTHThe field value indicating the eighth month of the year in the Gregorian and Julian calendars.static intDATEgetandsetThe field number indicates the day of the month.static intDAY_OF_MONTHgetandsetThe field number indicates the day of the month.static intDAY_OF_WEEKThe field number isgetandsetrepresents the day of the week.static intDAY_OF_WEEK_IN_MONTHgetandsetField number, indicating the ordinal of a day in the current month.static intDAY_OF_YEARgetandsetThe field number indicates the day number within the current year.static intDECEMBERMONTHField value indicating the twelfth month of the year in the Gregorian and Julian calendars.static intDST_OFFSETgetandsetThe field number indicating the daylight saving offset in milliseconds.static intERAgetandsetThe field number indicating the era, e.g., AD or BC in the Julian calendar.static intFEBRUARYMONTHThe field value indicating the second month of the year in the Gregorian and Julian calendars.static intFIELD_COUNTgetandsetThe number of distinct fields recognized.protected int[]fieldThe calendar field value of the currently set time of this calendar.static intFRIDAYDAY_OF_WEEKThe value of the field indicates Friday.static intHOURgetandsetThe field number indicates the hour of the morning or afternoon.static intHOUR_OF_DAYgetandsetThe field number indicates the hour of the day.protected boolean[]isSetA flag used to indicate whether the specified calendar field of the calendar is set.protected booleanisTimeSetif thentimethe value is validtimeTrue.static intJANUARYMONTHThe value of the field, representing the first month of the year in the Gregorian and Julian calendars.static intJULYMONTHThe field value indicating the seventh month of the year in the Gregorian and Julian calendars.static intJUNEMONTHThe value of the field, indicating the sixth month in the Gregorian and Julian calendars.static intLONGstatic intLONG_FORMATgetDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the long name used for formatting.static intLONG_STANDALONEgetDisplayNameandgetDisplayNamesofstyle descriptionsymbolRepresents stand-alone long names, such as month names as calendar headings.static intMARCHMONTHThe field value indicating the third month of the year in the Gregorian and Julian calendars.static intMAYMONTHThe value of the field, representing the fifth month of the year in the Gregorian and Julian calendars.static intMILLISECONDgetandsetThe field number represents the number of milliseconds within a second.static intMINUTEgetandsetThe field number represents the minutes within an hour.static intMONDAYDAY_OF_WEEKThe value of the field indicates Monday.static intMONTHgetandsetThe field number represents the month.static intNARROW_FORMATgetDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the narrow name used for formatting.static intNARROW_STANDALONEstatic intNOVEMBERMONTHThe value of the field representing the 11th month of the year in the Gregorian and Julian calendars.static intOCTOBERMONTHThe field value indicating the tenth month of the year in the Gregorian and Julian calendars.static intPMAM_PMThe value of the field, representing the period of the day from noon to just before midnight.static intSATURDAYrepresenting SaturdayDAY_OF_WEEKThe value of the field.static intSECONDgetandsetThe field number represents the second within the minute.static intSEPTEMBERMONTHThe field value indicating the ninth month of the year in the Gregorian and Julian calendars.static intSHORTstatic intSHORT_FORMATgetDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the short name used for formatting.static intSHORT_STANDALONEgetDisplayNameandgetDisplayNamesofstyle descriptionsymbolIndicates stand-alone short names, for example, month abbreviations as calendar headings.static intSUNDAYrepresenting SundayDAY_OF_WEEKThe value of the field.static intTHURSDAYDAY_OF_WEEKThe value of the field indicates Thursday.protected longtimeThe currently set time of this calendar, expressed in milliseconds after 00:00:00 Greenwich Mean Time on January 1, 1970.static intTUESDAYrepresenting TuesdayDAY_OF_WEEKThe value of the field.static intUNDECIMBERMONTHThe value of the field representing the 13th month of the year.static intWEDNESDAYDAY_OF_WEEKThe value of the field indicates Wednesday.static intWEEK_OF_MONTHgetandsetfield number,getsetthe number of weeks.static intWEEK_OF_YEARgetandsetThe field number represents the week number of the current year.static intYEARThe field number isgetandsetrepresents the year.static intZONE_OFFSETgetandsetField number, indicating the raw offset from GMT in milliseconds.
-
Method Summary
All methods Static method Instance Methods Abstract Methods Specific Methods Variables and types Methods Description abstract voidadd(int field, int amount)Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.booleanafter(Object when)Return thisCalendarwhether it represents the specifiedObjectThe time after the time represented.booleanbefore(Object when)Return thisCalendarwhether it represents the specifiedObjectThe time before the time represented.voidclear()Sets thisCalendarAll undefined calendar field values and time values (distanceEpoch'smillisecond offset).voidclear(int field)Sets thisCalendarGiven undefined calendar field values and time values (distanceEpoch'smillisecond offset).Objectclone()Creates and returns a copy of this object.intcompareTo(Calendar anotherCalendar)compare twoCalendarThe time value represented by the object (fromthe start of the Epochmillisecond offset).protected voidcomplete()Fills in any unset fields in the calendar fields.protected abstract voidcomputeFields()protected abstract voidcomputeTime()booleanequals(Object obj)Put thisCalendarwith the specifiedObject。intget(int field)Returns the value of the given calendar field.intgetActualMaximum(int field)Given thisCalendarthe time value, returns what the specified calendar field may haveCalendar。intgetActualMinimum(int field)Given thisCalendarthe time value, returns what the specified calendar field may haveCalendar。static Set<String>getAvailableCalendarTypes()Returns an unmodifiableSetwhich contains, in the runtime environmentCalendarall calendar types supported.static Locale[]getAvailableLocales()Returns an array of all locales,getInstancemethod cangetInstanceReturns a localized instance.StringgetCalendarType()Return thisCalendarof the calendar type.StringgetDisplayName(int field, int style, Locale locale)returns the givenstyleandlocaleCalendarfieldstring representation of the valuelocale。Map<String,Integer>getDisplayNames(int field, int style, Locale locale)returnMapcontaining the givenstyleandlocaleCalendarfieldAll names and their corresponding field values.intgetFirstDayOfWeek()Gets the first day of the week; For example,SUNDAYin the United States,MONDAYin France.abstract intgetGreatestMinimum(int field)Return thisCalendarThe greatest minimum value of the given calendar field of this instance.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 the specified locale.static CalendargetInstance(TimeZone zone)Gets a calendar using the specified time zone and the default locale.static CalendargetInstance(TimeZone zone, Locale aLocale)Gets a calendar with the specified time zone and locale.abstract intgetLeastMaximum(int field)Return thisCalendarThe least maximum value of the given calendar field of this instance.abstract intgetMaximum(int field)Return thisCalendarof the given calendar field of the instanceCalendar。intgetMinimalDaysInFirstWeek()Gets the minimum number of days required for the first week of the year; For example, if the first week is defined as the week containing the first day of the first month of the year, this method returns 1.abstract intgetMinimum(int field)Return thisCalendarof the given calendar field of the instanceCalendar。DategetTime()longgetTimeInMillis()Returns the time value of this Calendar in milliseconds.TimeZonegetTimeZone()Gets the time zone.intgetWeeksInWeekYear()Return thisCalendarthe week in the week representedCalendar。intgetWeekYear()Return thisCalendarrepresentedCalendar。inthashCode()Returns the hash code of this calendar.protected intinternalGet(int field)Returns the value of the given calendar field.booleanisLenient()Tells whether the date/time interpretation is lenient.booleanisSet(int field)Determines whether the given calendar field has a value set, including bygetThe case where a value is set by internal field calculations triggered by method calls.booleanisWeekDateSupported()Return thisCalendarWhether week date is supported.abstract voidroll(int field, boolean up)Add or subtract (up/down) a single unit of time on a given time field without changing larger fields.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 value of the calendar field.YEAR,MONTHandDAY_OF_MONTH。voidset(int year, int month, int date, int hourOfDay, int minute)Sets the value of the calendar field.YEAR,MONTH,DAY_OF_MONTH,HOUR_OF_DAYandMINUTE。voidset(int year, int month, int date, int hourOfDay, int minute, int second)Set the value in the fieldYEAR,MONTH,DAY_OF_MONTH,HOUR_OF_DAY,MINUTEandSECOND。voidsetFirstDayOfWeek(int value)Sets the first day of the week; For example,SUNDAYin the United States,MONDAYin France.voidsetLenient(boolean lenient)Specifies whether the date/time interpretation is lenient.voidsetMinimalDaysInFirstWeek(int value)Sets the minimum number of days required for the first week of the year; For example, if the first week is defined as the week containing the first day of the first month of the year, call this method with the value 1.voidsetTime(Date date)Uses the givenDateSets the time of this calendar.voidsetTimeInMillis(long millis)Sets this Calendar's current time from the given long value.voidsetTimeZone(TimeZone value)Sets the time zone using the given time zone value.voidsetWeekDate(int weekYear, int weekOfYear, int dayOfWeek)Sets this using the given date specifier.Calendarthe date - week year, day of week, and day of week.InstanttoInstant()Converts this object toInstant。StringtoString()Returns a string representation of this calendar.
-
-
-
Field Detail
-
ERA
public static final int ERA
getandsetThe field number indicating the era, e.g., AD or BC in the Julian calendar. This is a calendar-specific value; See the subclass documentation.- See also:
-
GregorianCalendar.AD,GregorianCalendar.BC, constant field value
-
YEAR
public static final int YEAR
getandsetThe field number represents the year. This is a calendar-specific value; See the subclass documentation.- See also:
- constant field value
-
MONTH
public static final int MONTH
getandsetThe field number represents the month. This is a calendar-specific value. The first month of the Gregorian and Julian calendar isJANUARY, i.e., 0; The last one depends on the number of months in a year.
-
WEEK_OF_YEAR
public static final int WEEK_OF_YEAR
getandsetThe field number indicates the week number of the year. bygetFirstDayOfWeek()andgetMinimalDaysInFirstWeek()The first week of the year, as defined, has a value of 1. The subclass defines the number of days preceding the first week of the year.WEEK_OF_YEARthe value of.
-
WEEK_OF_MONTH
public static final int WEEK_OF_MONTH
getandsetfield number representinggetthe number of weeks. bygetFirstDayOfWeek()andgetMinimalDaysInFirstWeek()The first week of the defined month has value 1. Subclasses define the value of the days before the first week of the month.WEEK_OF_MONTH。
-
DATE
public static final int DATE
getandsetThe field number indicates the day of the month. This isDAY_OF_MONTHa synonym for. The value of the first day of the month is 1.- See also:
-
DAY_OF_MONTH, constant field value
-
DAY_OF_MONTH
public static final int DAY_OF_MONTH
getandsetThe field number indicates the day of the month. This isDATEa synonym for. The value of the first day of the month is 1.- See also:
-
DATE, constant field value
-
DAY_OF_YEAR
public static final int DAY_OF_YEAR
getandsetThe field number indicates the day number within the current year. The first day of the year has a value of 1.- See also:
- constant field value
-
DAY_OF_WEEK
public static final int DAY_OF_WEEK
getandsetThe field number indicates the day of the week. this field valueSUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAYandSATURDAY。
-
DAY_OF_WEEK_IN_MONTH
public static final int DAY_OF_WEEK_IN_MONTH
getandsetField number indicating the ordinal number of the day of the week within the current month. andDAY_OF_WEEKFields together uniquely specify a day within a month. UnlikeWEEK_OF_MONTHandWEEK_OF_YEAR, the value of this fieldNotDepends ongetFirstDayOfWeek()orgetMinimalDaysInFirstWeek()。DAY_OF_MONTH 1To7always correspondsDAY_OF_WEEK_IN_MONTH 1;8to14corresponds toDAY_OF_WEEK_IN_MONTH 2, and so on.DAY_OF_WEEK_IN_MONTH 0RepresentsDAY_OF_WEEK_IN_MONTH 1the previous week. Negative values are counted from the end of the month; therefore, the last Sunday of a month is specified asDAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1。 Since negative values count backward, they are usually aligned differently within the month than positive values. For example, if a month has 31 days, thenDAY_OF_WEEK_IN_MONTH -1will overlapDAY_OF_WEEK_IN_MONTH 5and4end.- See also:
-
DAY_OF_WEEK,WEEK_OF_MONTH, constant field value
-
AM_PM
public static final int AM_PM
getandsetfield number representingHOURis before or after noon. For example, at 10:04 PM:AM_PMYesPM。- See also:
-
AM,PM,HOUR, constant field value
-
HOUR
public static final int HOUR
getandsetThe field number indicates the hour of the morning or afternoon.HOURUsed for the 12-hour clock (0 - 11). Noon and midnight are represented by 0, not 12. For example, at 10:04:15.250 PM,HOURis 10.- See also:
-
AM_PM,HOUR_OF_DAY, constant field value
-
HOUR_OF_DAY
public static final int HOUR_OF_DAY
getandsetThe field number indicates the hour of the day.HOUR_OF_DAYUsed for the 24-hour clock. For example, at 10:04 PM:HOUR_OF_DAYis 22.- See also:
-
HOUR, constant field value
-
MINUTE
public static final int MINUTE
getandsetThe field number represents the minutes within an hour. For example, at 10:04 PM:MINUTEis 4.- See also:
- constant field value
-
SECOND
public static final int SECOND
getandsetThe field number represents the second within the minute. For example, at 10:04 PM:SECONDis 15.- See also:
- constant field value
-
MILLISECOND
public static final int MILLISECOND
getandsetThe field number represents the number of milliseconds within a second. For example, at 10:04 PM:MILLISECONDis 250.- See also:
- constant field value
-
ZONE_OFFSET
public static final int ZONE_OFFSET
getandsetThe field number indicates the raw offset from GMT (in milliseconds).if
TimeZoneIf the implementation subclass supports historical GMT offset changes, this field reflects thisCalendarThe correct GMT offset value for the time zone.- See also:
- constant field value
-
DST_OFFSET
public static final int DST_OFFSET
getandsetThe field number indicating the daylight saving offset in milliseconds.if
TimeZoneIf the implementation subclass supports historical daylight saving time schedule changes, this field reflects thisCalendarThe correct daylight saving time offset value for the time zone.- See also:
- constant field value
-
FIELD_COUNT
public static final int FIELD_COUNT
getandsetThe number of different fields recognized. the field number range is0..FIELD_COUNT-1。- See also:
- constant field value
-
SUNDAY
public static final int SUNDAY
representing SundayDAY_OF_WEEKThe value of the field.- See also:
- constant field value
-
MONDAY
public static final int MONDAY
DAY_OF_WEEKThe value of the field indicates Monday.- See also:
- constant field value
-
TUESDAY
public static final int TUESDAY
representing TuesdayDAY_OF_WEEKThe value of the field.- See also:
- constant field value
-
WEDNESDAY
public static final int WEDNESDAY
DAY_OF_WEEKThe value of the field indicates Wednesday.- See also:
- constant field value
-
THURSDAY
public static final int THURSDAY
DAY_OF_WEEKThe value of the field indicates Thursday.- See also:
- constant field value
-
FRIDAY
public static final int FRIDAY
representing FridayDAY_OF_WEEKThe value of the field.- See also:
- constant field value
-
SATURDAY
public static final int SATURDAY
representing SaturdayDAY_OF_WEEKThe value of the field.- See also:
- constant field value
-
JANUARY
public static final int JANUARY
MONTHThe field value indicating the first month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
FEBRUARY
public static final int FEBRUARY
MONTHThe field value indicating the second month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
MARCH
public static final int MARCH
MONTHThe field value indicating the third month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
APRIL
public static final int APRIL
MONTHThe field value indicating the fourth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
MAY
public static final int MAY
MONTHThe value of the field, indicating the fifth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
JUNE
public static final int JUNE
MONTHThe value of the field, indicating the sixth month in the Gregorian and Julian calendars.- See also:
- constant field value
-
JULY
public static final int JULY
MONTHThe field value indicating the seventh month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
AUGUST
public static final int AUGUST
MONTHThe field value indicating the eighth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
SEPTEMBER
public static final int SEPTEMBER
MONTHThe field value indicating the ninth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
OCTOBER
public static final int OCTOBER
MONTHThe field value indicating the tenth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
NOVEMBER
public static final int NOVEMBER
MONTHField value indicating the eleventh month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
DECEMBER
public static final int DECEMBER
MONTHField value indicating the twelfth month of the year in the Gregorian and Julian calendars.- See also:
- constant field value
-
UNDECIMBER
public static final int UNDECIMBER
MONTHThe value of the field representing the 13th month of the year. AlthoughGregorianCalendarThis value is not used, but the calendar will do so.- See also:
- constant field value
-
AM
public static final int AM
AM_PMThe value of the field, representing the period of the day from midnight to just before noon.- See also:
- constant field value
-
PM
public static final int PM
AM_PMThe value of the field, representing the period of the day from noon to just before midnight.- See also:
- constant field value
-
ALL_STYLES
public static final int ALL_STYLES
getDisplayNamesThe style specifier, representing the names of all styles, such as 'January' and 'Jan'.- Starting from the following version:
- 1.6
- See also:
-
SHORT_FORMAT,LONG_FORMAT,SHORT_STANDALONE,LONG_STANDALONE,SHORT,LONG, constant field value
-
SHORT
public static final int SHORT
- Starting from the following version:
- 1.6
- See also:
-
SHORT_STANDALONE,LONG, constant field value
-
LONG
public static final int LONG
- Starting from the following version:
- 1.6
- See also:
-
LONG_STANDALONE,SHORT, constant field value
-
NARROW_FORMAT
public static final int NARROW_FORMAT
getDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the narrow name used for formatting. Narrow names are usually a single string, such as 'M' for Monday.- Starting from the following version:
- 1.8
- See also:
-
NARROW_STANDALONE,SHORT_FORMAT,LONG_FORMAT, constant field value
-
NARROW_STANDALONE
public static final int NARROW_STANDALONE
getDisplayNameandgetDisplayNamesofstyle descriptionsymbol , IndependentIndicates narrow names. Narrow names are usually a single string, such as 'M' for Monday.- Starting from the following version:
- 1.8
- See also:
-
NARROW_FORMAT,SHORT_STANDALONE,LONG_STANDALONE, constant field value
-
SHORT_FORMAT
public static final int SHORT_FORMAT
getDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the short name used for formatting.- Starting from the following version:
- 1.8
- See also:
-
SHORT_STANDALONE,LONG_FORMAT,LONG_STANDALONE, constant field value
-
LONG_FORMAT
public static final int LONG_FORMAT
getDisplayNameandgetDisplayNamesofstyle descriptionsymbol, indicating the long name used for formatting.- Starting from the following version:
- 1.8
- See also:
-
LONG_STANDALONE,SHORT_FORMAT,SHORT_STANDALONE, constant field value
-
SHORT_STANDALONE
public static final int SHORT_STANDALONE
getDisplayNameandgetDisplayNamesofstyle descriptionsymbolIndicates stand-alone short names, for example, month abbreviations as calendar headings.- Starting from the following version:
- 1.8
- See also:
-
SHORT_FORMAT,LONG_FORMAT,LONG_STANDALONE, constant field value
-
LONG_STANDALONE
public static final int LONG_STANDALONE
getDisplayNameandgetDisplayNamesofstyle descriptionsymbolRepresents stand-alone long names, such as month names as calendar headings.- Starting from the following version:
- 1.8
- See also:
-
LONG_FORMAT,SHORT_FORMAT,SHORT_STANDALONE, constant field value
-
Fields
protected int[] fields
The calendar field value of the currently set time of this calendar. This is aFIELD_COUNTInteger array, index value isERAtoDST_OFFSET。
-
isSet
protected boolean[] isSet
A flag used to indicate whether the specified calendar field of the calendar is set. The new object has no fields set. After the first call to the method that generates the fields, they will all remain set thereafter. this is a set ofFIELD_COUNTBoolean value, the index value isERAtoDST_OFFSET。
-
time
protected long time
The currently set time of this calendar, expressed in milliseconds after 00:00:00 Greenwich Mean Time on January 1, 1970.- See also:
-
isTimeSet
-
isTimeSet
protected boolean isTimeSet
if thentimethe value is validtimeTrue. by changing the itemfield[]invalidates the time.- See also:
-
time
-
areFieldsSet
protected boolean areFieldsSet
iffields[]Synchronized with the currently set time,fields[]True。 If false, the next attempt to fetch the field value will force a recomputation of the current value.timeof all fields.
-
-
Constructor Detail
-
Calendar
protected Calendar()
Using the default time zone and the defaultFORMATThe locale constructs a calendar.- See also:
-
TimeZone.getDefault()
-
-
Method Detail
-
getInstance
public static Calendar getInstance()
Gets a calendar using the default time zone and locale. returnedCalendarBased on the current time in the default time zone, defaults toFORMATlocale.If the locale contains the time zone "tz"Unicode extension, then the time zone is used.
- Result
- calendar.
-
getInstance
public static Calendar getInstance(TimeZone zone)
Gets a calendar using the specified time zone and the default locale. returnedCalendarbased on the current time in the given time zone, with the defaultFORMATlocale.- Parameter
-
zone- The time zone to use. - Result
- calendar.
-
getInstance
public static Calendar getInstance(Locale aLocale)
Gets a calendar using the default time zone and the specified locale. returnedCalendarBased on the current time in the default time zone with the given locale.If the locale contains the time zone "tz"Unicode extension, then the time zone is used.
- Parameter
-
aLocale- The locale for week data. - Result
- calendar.
-
getInstance
public static Calendar getInstance(TimeZone zone, Locale aLocale)
Gets a calendar with the specified time zone and locale. returnedCalendarBased on the current time in the given time zone with the given locale.- Parameter
-
zone- The time zone to use. -
aLocale- The locale for week data. - Result
- calendar.
-
getAvailableLocales
public static Locale[] getAvailableLocales()
returngetInstanceThe method can return an array of all locales for localized instances. The returned array must contain at least one equal toLocale.USofLocaleinstance.- Result
- A set of locales whose localized
CalendarAn instance is available.
-
computeTime
protected abstract void computeTime()
- See also:
-
complete(),computeFields()
-
computeFields
protected abstract void computeFields()
The current millisecond time value is converted totimethe calendar field value offields[]。 This allows you to synchronize the calendar field values with the new time set for the calendar. TimeWill notrecalculate first; Recompute the time, then the fields, callcomplete()method.- See also:
-
computeTime()
-
getTime
public final Date getTime()
Returns a representation of thisCalendarthe time value (distanceEpoch'smillisecond offset) ofDateObject.- Result
-
DateRepresents a time value. - See also:
-
setTime(Date),getTimeInMillis()
-
setTime
public final void setTime(Date date)
Uses the givenDateSets the time of this calendar.Note: use
Date(Long.MAX_VALUE)orDate(Long.MIN_VALUE)CallsetTime()may be fromget()Produces an incorrect field value.- Parameter
-
date- The given date. - See also:
-
getTime(),setTimeInMillis(long)
-
getTimeInMillis
public long getTimeInMillis()
Returns the time value of this Calendar in milliseconds.- Result
- The current time in UTC milliseconds since the epoch.
- See also:
-
getTime(),setTimeInMillis(long)
-
setTimeInMillis
public void setTimeInMillis(long millis)
Sets this Calendar's current time from the given long value.- Parameter
-
millis- The new time in UTC milliseconds since the epoch. - See also:
-
setTime(Date),getTimeInMillis()
-
get
public int get(int field)
Returns the value of the given calendar field. In lenient mode, all calendar fields are normalized. In non-lenient mode, all calendar fields are validated, and if any calendar field has an out-of-range value, this method will throw an exception. normalization and validation bycomplete()Method handling, which depends on the calendar system.- Parameter
-
field- The given calendar field. - Result
- The value of the given calendar field.
- Exception
-
ArrayIndexOutOfBoundsException- If the specified field is out of range (field < 0 || field >= FIELD_COUNT)。 - See also:
-
set(int,int),complete()
-
internalGet
protected final int internalGet(int field)
Returns the value of the given calendar field. This method does not involve normalization or validation of field values.- Parameter
-
field- The given calendar field. - Result
- The value of the given calendar field.
- See also:
-
get(int)
-
set
public void set(int field, int value)Sets the given calendar field to the given value. This method does not interpret the value regardless of the lenient mode.- Parameter
-
field- The given calendar field. -
value- The value to be set for the given calendar field. - Exception
-
ArrayIndexOutOfBoundsException- If the specified field is out of range (field < 0 || field >= FIELD_COUNT)。 In non-lenient mode. - See also:
-
set(int,int,int),set(int,int,int,int,int),set(int,int,int,int,int,int),get(int)
-
set
public final void set(int year, int month, int date)Sets the value of the calendar field.YEAR,MONTHandDAY_OF_MONTH。 Preserves the previous values of other calendar fields. if not needed,Please firstCallclear()。- Parameter
-
year- Used to setYEARthe value of the calendar field. -
month- used to setMONTHThe value of the calendar field. month value is zero-based. For example, 0 represents January. -
date- Used to setDAY_OF_MONTHthe value of the calendar field. - See also:
-
set(int,int),set(int,int,int,int,int),set(int,int,int,int,int,int)
-
set
public final void set(int year, int month, int date, int hourOfDay, int minute)Sets the value of the calendar field.YEAR,MONTH,DAY_OF_MONTH,HOUR_OF_DAYandMINUTE。 Retains the previous values of other fields. if not needed,Please firstCallclear()。- Parameter
-
year- Used to setYEARthe value of the calendar field. -
month- used to setMONTHThe value of the calendar field. month value is zero-based. For example, 0 represents January. -
date- Used to setDAY_OF_MONTHthe value of the calendar field. -
hourOfDay- Used to setHOUR_OF_DAYthe value of the calendar field. -
minute- Used to setMINUTEthe value of the calendar field. - See also:
-
set(int,int),set(int,int,int),set(int,int,int,int,int,int)
-
set
public final void set(int year, int month, int date, int hourOfDay, int minute, int second)Set the value in the fieldYEAR,MONTH,DAY_OF_MONTH,HOUR_OF_DAY,MINUTEandSECOND。 Retains the previous values of other fields. if not needed,Please firstCallclear()。- Parameter
-
year- Used to setYEARthe value of the calendar field. -
month- used to setMONTHThe value of the calendar field. month value is zero-based. For example, 0 represents January. -
date- Used to setDAY_OF_MONTHthe value of the calendar field. -
hourOfDay- Used to setHOUR_OF_DAYthe value of the calendar field. -
minute- Used to setMINUTEthe value of the calendar field. -
second- Used to setSECONDthe value of the calendar field. - See also:
-
set(int,int),set(int,int,int),set(int,int,int,int,int)
-
clear
public final void clear()
Sets thisCalendarAll undefined calendar field values and time values (withEpoch'smillisecond offset). this meansisSet()will return for all calendar fieldsfalse, date and time calculations treat the field as if it had never been set.CalendarImplementation classes may use their specific default field values for date/time calculations. For example, ifYEARIf the field value is undefined, thenGregorianCalendarusing 1970.- See also:
-
clear(int)
-
clear
public final void clear(int field)
Sets thisCalendarThe given calendar field value and time value of undefined (distanceEpoch'smillisecond offset). this meansisSet(field)will returnfalseand the date and time calculation treats the field as if it was never set.CalendarImplementation classes can use field-specific default values for date and time calculations.of
HOUR_OF_DAY,HOURandAM_PMfields are processed independently, andthe resolution rule for the time of dayis applied. Clearing one of the fields does not reset this.Calendarthe hour value. Usageset(Calendar.HOUR_OF_DAY, 0)reset the hour value.- Parameter
-
field- The calendar field to clear. - See also:
-
clear()
-
isSet
public final boolean isSet(int field)
Determines whether the given calendar field has a value set, including bygetThe case where a value is set by internal field calculations triggered by method calls.- Parameter
-
field- The calendar field to test. - Result
-
trueIf the given calendar field has a value set; otherwise isfalse。
-
getDisplayName
public String getDisplayName(int field, int style, Locale locale)
returns the givenstyleandlocaleCalendarfieldstring representation of the valuelocale。 If there is no applicable string representation, then returnsnull。 If the string representation applies to the given calendarfieldthen this method callsget(field)to get the calendarfieldvalue.for example, if this
CalendarYesGregorianCalendarand its date is 2005-01-01, thenMONTHThe string representation of the field will be 'January' in the long style or 'Jan' in the short style in the English locale. but,DAY_OF_MONTHThe field has no available string representation; this method will returnnull。The default implementation supports the calendar fields therein.
DateFormatSymbolswith the given namelocale。- Parameter
-
field- The calendar field whose string representation is returned. -
style- The style applied to the string representation; One ofSHORT_FORMAT(SHORT),SHORT_STANDALONE,LONG_FORMAT(LONG),LONG_STANDALONE,NARROW_FORMAT, orNARROW_STANDALONE。 -
locale- The locale of the string representation (bylocaleAny specified calendar type will be ignored) - Result
- Given
fieldgiven instylestring representationstyle, if there is no applicable string representationstyle,null。 - Exception
-
IllegalArgumentException- iffieldorstyleinvalid, or thisCalendarNot lenient and any calendar field has an invalid value -
NullPointerException- iflocaleIs empty - Starting from the following version:
- 1.6
-
getDisplayNames
public Map<String,Integer> getDisplayNames(int field, int style, Locale locale)
returnMapcontaining the givenstyleandlocaleCalendarfieldAll names and their corresponding field values. for example, if thisCalendarYesGregorianCalendar, the returned map will contain "Jan" toJANUARY, "Feb" toFEBRUARY, and so on, in the English locale.shortin the style.Because single characters are used, the abbreviated names may not be unique, for example, 'S' for Sunday and Saturday. In this case, the short names are not included in the returned
Map。The values of other calendar fields can be considered to determine a set of display names. for example, if this
Calendaris a lunisolar calendar system andYEARIf the year value given by the field has a leap month, this method will return the month name containing the leap month name, and the month name will be mapped to a year-specific month name.the default implementation supports
DateFormatSymbolsMediumThe contained display names. For example, iffieldYesMONTHAlsostyleYesALL_STYLES, then this method returnsMapwhich containsDateFormatSymbols.getShortMonths()andDateFormatSymbols.getMonths()All returned strings.- Parameter
-
field- The calendar field for which to return the display name. -
style- The style applied to the string representation; One ofSHORT_FORMAT(SHORT),SHORT_STANDALONE,LONG_FORMAT(LONG),LONG_STANDALONE,NARROW_FORMAT, orNARROW_STANDALONE -
locale- The locale for the display name. - Result
- a
Mapincluded in all display namesstyleandlocaleand their field values, ornullif no display name is definedfield - Exception
-
IllegalArgumentException- iffieldorstyleinvalid, or thisCalendarNot lenient and any calendar field has an invalid value -
NullPointerException- iflocaleIs empty - Starting from the following version:
- 1.6
-
complete
protected void complete()
Fills in any unset fields in the calendar fields. First, if the time value has not yet been calculated based on the calendar field values (distanceEpoch'smillisecond offset), then callcomputeTime()method. Then, callcomputeFields()Method to compute all calendar field values.
-
getAvailableCalendarTypes
public static Set<String> getAvailableCalendarTypes()
Returns an unmodifiableSetwhich contains, in the runtime environmentCalendarall calendar types supported. Available calendar types can be used forUnicode locale extensions 。 returnedSetcontains at least"gregory"。 The calendar type does not contain aliases, such as"gregorian"("gregory"。- Result
- An unmodifiable set containing all available calendar types
Set - Starting from the following version:
- 1.8
- See also:
-
getCalendarType(),Calendar.Builder.setCalendarType(String),Locale.getUnicodeLocaleType(String)
-
getCalendarType
public String getCalendarType()
Return thisCalendarof the calendar type. The calendar type isUnicode Locale Data Markup Language (LDML)defined by the specification.The default implementation of this method returns this
Calendarthe class name of the instance. Any subclass that implements a calendar system defined by LDML should override this method to return the appropriate calendar type.- Result
- the calendar type defined by LDML or this
Calendarthe class name of the instance - Starting from the following version:
- 1.8
- See also:
-
Locale extensions ,
Locale.Builder.setLocale(Locale),Locale.Builder.setUnicodeLocaleKeyword(String, String)
-
equals
public boolean equals(Object obj)
Put thisCalendarwith the specifiedObject。 if and only if the argument is of the same calendar systemCalendarwhen the object, the result istrue, which represents the same as this object.Calendarthe same time value under the parameter (distanceEpoch'smillisecond offset).of
CalendarThe parameter is the value represented byisLenient,getFirstDayOfWeek,getMinimalDaysInFirstWeekandgetTimeZonemethod. if twoCalendarIf there is any difference between the parameters, then this method returnsfalse。Usage
compareToThe method compares only time values.- Override:
-
equalsClassObject - Parameter
-
obj- The object to be compared with. - Result
-
trueif this object equalsobj; otherwise isfalse。 - See also:
-
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns the hash code of this calendar.- Override:
-
hashCode, classObject - Result
- The hash code value of this object.
- Starting from the following version:
- 1.2
- See also:
-
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
before
public boolean before(Object when)
Return thisCalendarwhether it represents the specifiedObjectThe time before the time represented. This method is equivalent to:if and only ifcompareTo(when) < 0whenYesCalendarinstance. Otherwise, this method returnsfalse。- Parameter
-
when- the object to be comparedObject - Result
-
trueIf at this pointCalendaris before the time represented by the following expressionwhen; otherwise isfalse。 - See also:
-
compareTo(Calendar)
-
after
public boolean after(Object when)
Return thisCalendarwhether it represents the specifiedObjectThe time after the time represented. This method is equivalent to:if and only ifcompareTo(when) > 0whenYesCalendarinstance. Otherwise, this method returnsfalse。- Parameter
-
when- the object to be comparedObject - Result
-
trueif thisCalendartime ofwheninwhenthe time represented; otherwise isfalse。 - See also:
-
compareTo(Calendar)
-
compareTo
public int compareTo(Calendar anotherCalendar)
compare twoCalendarThe time value represented by the object (fromthe start of the Epochmillisecond offset).- Specified by:
-
compareToin interfaceComparable<Calendar> - Parameter
-
anotherCalendar- the object to be comparedCalendar。 - Result
-
Value
0If the time represented by the specified parameter is equal to the time represented by this.Calendar; if thisCalendarthe time is earlier than the time represented by the parameter, then the value is less than0; if thisCalendarthe time is after the time represented by the parameter, then the value is greater than0。 - Exception
-
NullPointerException- if the specifiedCalendarYesnull。 -
IllegalArgumentException- If the specified field cannot be obtained due to any invalid calendar valueCalendarobject's time value. - Starting from the following version:
- 1.5
-
add
public abstract void add(int field, int amount)Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve this by calling the following method:add(Calendar.DAY_OF_MONTH, -5)。- Parameter
-
field- the calendar field. -
amount- The amount of date or time to be added to the field. - See also:
-
roll(int,int),set(int,int)
-
roll
public abstract void roll(int field, boolean up)Add or subtract (up/down) a single unit of time on a given time field without changing larger fields. For example, to move the current date one day earlier, you can achieve it by calling:roll(Calendar.DATE,true)。 When rolling on the year or Calendar.YEAR field, it will roll the year value, ranging between 1 and by calling
getMaximum(Calendar.YEAR)between the returned values. When rolling on the month or Calendar.MONTH field, other fields (such as date) may conflict and need to be changed. For example, rolling the month on the date 01/31/96 will result in 02/29/96. When rolling on the hour or Calendar.HOUR_OF_DAY field, it will roll the hour value within the range from 0 to 23, starting at zero.- Parameter
-
field- the time field. -
up- Indicates whether to add or roll the value of the specified time field. Use true if scrolling, otherwise use false. - See also:
-
add(int,int),set(int,int)
-
roll
public void roll(int field, int amount)Adds the specified (signed) amount to the specified calendar field without changing larger fields. Negative numbers indicate downward scrolling.Note:
CalendarThe default implementation above simply repeatedly calls the version that rolls by one unit.roll()。 This may not always do the right thing. For example, ifDAY_OF_MONTHIf the field is 31, then rolling to February sets it to 28. This function'sGregorianCalendarA version can resolve this issue. Other subclasses should also provide an override of this method to do the right thing.- Parameter
-
field- the calendar field. -
amount- The amount to add to the calendar.fieldthe signed amount. - Starting from the following version:
- 1.2
- See also:
-
roll(int,boolean),add(int,int),set(int,int)
-
setTimeZone
public void setTimeZone(TimeZone value)
Sets the time zone using the given time zone value.- Parameter
-
value- The given time zone.
-
getTimeZone
public TimeZone getTimeZone()
Gets the time zone.- Result
- The time zone object associated with this calendar.
-
setLenient
public void setLenient(boolean lenient)
Specifies whether the date/time interpretation is lenient. ThroughLooseofExplanation,诸For example“1996year2month942”ofClassdayperiodwillBy视isEquivalent to1996year2month1dayafterof the941天。Through严格(notLoose) ofExplanation,这sampleofdayperiodwill导致Example外ByThrow. The default value is lenient.- Parameter
-
lenient-trueTo enable lenient mode;falsewhether to close. - See also:
-
isLenient(),DateFormat.setLenient(boolean)
-
isLenient
public boolean isLenient()
Tells whether the date/time interpretation is lenient.- Result
-
trueIf this calendar's interpretation mode is lenient; otherwise isfalse。 - See also:
-
setLenient(boolean)
-
setFirstDayOfWeek
public void setFirstDayOfWeek(int value)
Sets the first day of the week; For example,SUNDAYin the United States,MONDAYin France.- Parameter
-
value- The first day of the week. - See also:
-
getFirstDayOfWeek(),getMinimalDaysInFirstWeek()
-
getFirstDayOfWeek
public int getFirstDayOfWeek()
Gets the first day of the week; For example,SUNDAYin the United States,MONDAYin France.- Result
- The first day of the week.
- See also:
-
setFirstDayOfWeek(int),getMinimalDaysInFirstWeek()
-
setMinimalDaysInFirstWeek
public void setMinimalDaysInFirstWeek(int value)
Sets the minimum number of days required for the first week of the year; For example, if the first week is defined as the week containing the first day of the first month of the year, call this method with the value 1. If it must be a whole week, use the value 7.- Parameter
-
value- The minimum number of days required for the first week of the year. - See also:
-
getMinimalDaysInFirstWeek()
-
getMinimalDaysInFirstWeek
public int getMinimalDaysInFirstWeek()
Gets the minimum number of days required for the first week of the year; For example, ifNo.oneweekis defined ascontains ayearin theamonthof theone天of那oneweek, then this method returns1.ifplaceNeedthe mostsmall天numberRequiredYes整week, then this method returns7。- Result
- The minimum number of days required for the first week of the year.
- See also:
-
setMinimalDaysInFirstWeek(int)
-
isWeekDateSupported
public boolean isWeekDateSupported()
Return thisCalendarWhether week date is supported.The default implementation of this method returns
false。- Result
-
trueif thisCalendarsupports week date; otherwise isfalse。 - Starting from the following version:
- 1.7
- See also:
-
getWeekYear(),setWeekDate(int,int,int),getWeeksInWeekYear()
-
getWeekYear
public int getWeekYear()
Return thisCalendarrepresentedCalendar。 The week year is synchronized with the week cycle. first day of the first weekis the first day of the week.The default implementation of this method throws
UnsupportedOperationException。- Result
- This
CalendarOf thisCalendar - Exception
-
UnsupportedOperationException- if thisCalendarDoes not support any week-year numbering. - Starting from the following version:
- 1.7
- See also:
-
isWeekDateSupported(),getFirstDayOfWeek(),getMinimalDaysInFirstWeek()
-
setWeekDate
public void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek)Sets this using the given date specifier.Calendarof the date - week-year, week, and day-of-week.and
setThe method differs, all calendar fields andtimeThe values are all computed when returned.if
weekOfYearoutside the valid week-year rangeweekYear, thisweekYearitemsweekOfYearValues are adjusted in lenient mode, orIllegalArgumentExceptionthrows in non-lenient mode.The default implementation of this method throws
UnsupportedOperationException。- Parameter
-
weekYear- the week-based year -
weekOfYear- the week number based onweekYear -
dayOfWeek- the day-of-week value:DAY_OF_WEEKOne of the field constants:SUNDAY,...,SATURDAY。 - Exception
-
IllegalArgumentException- If any given date specifier is invalid, or any calendar field is inconsistent with the given date specifier in non-lenient mode -
UnsupportedOperationException- if thisCalendarDoes not support any week-year numbering. - Starting from the following version:
- 1.7
- See also:
-
isWeekDateSupported(),getFirstDayOfWeek(),getMinimalDaysInFirstWeek()
-
getWeeksInWeekYear
public int getWeeksInWeekYear()
Return thisCalendarThe week in the represented week-yearCalendar。The default implementation of this method throws
UnsupportedOperationException。- Result
- the week number in the year.
- Exception
-
UnsupportedOperationException- if thisCalendarDoes not support any week-year numbering. - Starting from the following version:
- 1.7
- See also:
-
WEEK_OF_YEAR,isWeekDateSupported(),getWeekYear(),getActualMaximum(int)
-
getMinimum
public abstract int getMinimum(int field)
Return thisCalendarof the given calendar field of the instanceCalendar。 the minimum value is defined asgetThe method returns the minimum value for any possible time value. The minimum value depends on the instance's calendar system-specific parameters.- Parameter
-
field- Calendar field. - Result
- The minimum value of the given calendar field.
- See also:
-
getMaximum(int),getGreatestMinimum(int),getLeastMaximum(int),getActualMinimum(int),getActualMaximum(int)
-
getMaximum
public abstract int getMaximum(int field)
Return thisCalendarof the given calendar field of the instanceCalendar。 the maximum value is defined asgetThe method returns the maximum value for any possible time value. The maximum value depends on the instance's calendar system-specific parameters.- Parameter
-
field- Calendar field. - Result
- The maximum value of the given calendar field.
- See also:
-
getMinimum(int),getGreatestMinimum(int),getLeastMaximum(int),getActualMinimum(int),getActualMaximum(int)
-
getGreatestMinimum
public abstract int getGreatestMinimum(int field)
Return thisCalendarThe greatest minimum value of the given calendar field of this instance. The greatest minimum value is defined asgetActualMinimum(int)The maximum value returned for any possible time value. The greatest minimum value depends on the calendar-system-specific parameters of the instance.- Parameter
-
field- Calendar field. - Result
- The smallest minimum value of the given calendar field.
- See also:
-
getMinimum(int),getMaximum(int),getLeastMaximum(int),getActualMinimum(int),getActualMaximum(int)
-
getLeastMaximum
public abstract int getLeastMaximum(int field)
Return thisCalendarThe least maximum value of the given calendar field of this instance. The least maximum value is defined asgetActualMaximum(int)returned for any possible time valueminimum value 。 The minimum of the minimum values depends on the calendar-system-specific parameters of the instance. For example,CalendarThe 28 returned for the Gregorian calendar systemDAY_OF_MONTHfield, since the 28th is the last day of February, the shortest month in a common year, in this calendar.- Parameter
-
field- Calendar field. - Result
- The lowest maximum value of the given calendar field.
- See also:
-
getMinimum(int),getMaximum(int),getGreatestMinimum(int),getActualMinimum(int),getActualMaximum(int)
-
getActualMinimum
public int getActualMinimum(int field)
Given thisCalendarthe time value, returns what the specified calendar field may haveCalendar。The default implementation of this method uses an iterative algorithm to determine the actual minimum value for the calendar field. If possible, subclasses should override it with a more efficient implementation - in many cases, they can simply return
getMinimum()。- Parameter
-
field- Calendar field - Result
- this
Calendarof the time value of the given calendar fieldCalendar - Starting from the following version:
- 1.2
- See also:
-
getMinimum(int),getMaximum(int),getGreatestMinimum(int),getLeastMaximum(int),getActualMaximum(int)
-
getActualMaximum
public int getActualMaximum(int field)
Given thisCalendarthe time value, returns what the specified calendar field may haveCalendar。 For example,MONTHThe actual maximum value of the field is 12 in some years, and 13 in other years in the Hebrew calendar system.The default implementation of this method uses an iterative algorithm to determine the actual maximum value for the calendar field. If possible, subclasses should override it with a more efficient implementation.
- Parameter
-
field- Calendar field - Result
- this
Calendarof the time value of the given calendar fieldCalendar - Starting from the following version:
- 1.2
- See also:
-
getMinimum(int),getMaximum(int),getGreatestMinimum(int),getLeastMaximum(int),getActualMinimum(int)
-
clone
public Object clone()
Creates and returns a copy of this object.
-
toString
public String toString()
Returns a string representation of this calendar. This method is for debugging purposes only; the format of the returned string may vary between implementations. The returned string may be empty, but may not benull。
-
-