Month
is an enum representing the 12 months of the year -
January, February, March, April, May, June, July, August, September, October,
November and December.
In addition to the textual enum name, each month-of-year has an int
value.
The int
value follows normal usage and the ISO-8601 standard,
from 1 (January) to 12 (December). It is recommended that applications use the enum
rather than the int
value to ensure code clarity.
Do not use ordinal()
to obtain the numeric representation of Month
.
Use getValue()
instead.
This enum represents a common concept that is found in many calendar systems. As such, this enum may be used by any calendar system that has the month-of-year concept defined exactly equivalent to the ISO-8601 calendar system.
Implementation Specification
This is an immutable and thread-safe enum.
Modifier and Type | Field and Description |
---|---|
public static final Month | APRIL
The singleton instance for the month of April with 30 days. |
public static final Month | AUGUST
The singleton instance for the month of August with 31 days. |
public static final Month | DECEMBER
The singleton instance for the month of December with 31 days. |
private static final Month[] | ENUMS
Private cache of all the constants. |
public static final Month | FEBRUARY
The singleton instance for the month of February with 28 days, or 29 in a leap year. |
public static final Month | JANUARY
The singleton instance for the month of January with 31 days. |
public static final Month | JULY
The singleton instance for the month of July with 31 days. |
public static final Month | JUNE
The singleton instance for the month of June with 30 days. |
public static final Month | MARCH
The singleton instance for the month of March with 31 days. |
public static final Month | MAY
The singleton instance for the month of May with 31 days. |
public static final Month | NOVEMBER
The singleton instance for the month of November with 30 days. |
public static final Month | OCTOBER
The singleton instance for the month of October with 31 days. |
public static final Month | SEPTEMBER
The singleton instance for the month of September with 30 days. |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public Temporal | Returns: the adjusted object, not nullthe target object to be adjusted, not null temporal)Implements java. Adjusts the specified temporal object to have this month-of-year. |
public int | Returns: the day of year corresponding to the first day of this month, from 1 to 336true if the length is required for a leap year leapYear)Gets the day-of-year corresponding to the first day of this month. |
public Month | Returns: the first month of the quarter corresponding to this month, not nullGets the month corresponding to the first month of this quarter. |
public static Month | Returns: the month-of-year, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
public int | Returns: the value for the field, within the valid range of valuesthe field to get, not null field)Overrides default java. Gets the value of the specified field from this month-of-year as an |
public String | Returns: the text value of the month-of-year, not nullthe length of the text required, not null style, Locale the locale to use, not null locale)Gets the textual representation, such as 'Jan' or 'December'. |
public long | Returns: the value for the fieldthe field to get, not null field)Implements java. Gets the value of the specified field from this month-of-year as a |
public int | Returns: the month-of-year, from 1 (January) to 12 (December)Gets the month-of-year |
public boolean | Returns: true if the field is supported on this month-of-year, false if notthe field to check, null returns false field)Implements java. Checks if the specified field is supported. |
public int | Returns: the length of this month in days, from 28 to 31true if the length is required for a leap year leapYear)Gets the length of this month in days. |
public int | Returns: the maximum length of this month in days, from 29 to 31Gets the maximum length of this month in days. |
public int | Returns: the minimum length of this month in days, from 28 to 31Gets the minimum length of this month in days. |
public Month | Returns: the resulting month, not nullthe months to subtract, positive or negative months)Returns the month-of-year that is the specified number of months before this one. |
public static Month | Returns: the month-of-year, not nullthe month-of-year to represent, from 1 (January) to 12 (December) month)Obtains an instance of |
public Month | Returns: the resulting month, not nullthe months to add, positive or negative months)Returns the month-of-year that is the specified number of months after this one. |
public < the type of the result R> R | Returns: the query result, null may be returned (defined by the query)the query to invoke, not null query)Overrides default java. Queries this month-of-year using the specified query. |
public ValueRange | Returns: the range of valid values for the field, not nullthe field to query the range for, not null field)Overrides default java. Gets the range of valid values for the specified field. |
public static Month | |
public static Month[] |
APRIL | back to summary |
---|---|
public static final Month APRIL The singleton instance for the month of April with 30 days.
This has the numeric value of |
AUGUST | back to summary |
---|---|
public static final Month AUGUST The singleton instance for the month of August with 31 days.
This has the numeric value of |
DECEMBER | back to summary |
---|---|
public static final Month DECEMBER The singleton instance for the month of December with 31 days.
This has the numeric value of |
ENUMS | back to summary |
---|---|
private static final Month[] ENUMS Private cache of all the constants. |
FEBRUARY | back to summary |
---|---|
public static final Month FEBRUARY The singleton instance for the month of February with 28 days, or 29 in a leap year.
This has the numeric value of |
JANUARY | back to summary |
---|---|
public static final Month JANUARY The singleton instance for the month of January with 31 days.
This has the numeric value of |
JULY | back to summary |
---|---|
public static final Month JULY The singleton instance for the month of July with 31 days.
This has the numeric value of |
JUNE | back to summary |
---|---|
public static final Month JUNE The singleton instance for the month of June with 30 days.
This has the numeric value of |
MARCH | back to summary |
---|---|
public static final Month MARCH The singleton instance for the month of March with 31 days.
This has the numeric value of |
MAY | back to summary |
---|---|
public static final Month MAY The singleton instance for the month of May with 31 days.
This has the numeric value of |
NOVEMBER | back to summary |
---|---|
public static final Month NOVEMBER The singleton instance for the month of November with 30 days.
This has the numeric value of |
OCTOBER | back to summary |
---|---|
public static final Month OCTOBER The singleton instance for the month of October with 31 days.
This has the numeric value of |
SEPTEMBER | back to summary |
---|---|
public static final Month SEPTEMBER The singleton instance for the month of September with 30 days.
This has the numeric value of |
Month | back to summary |
---|---|
private Month() |
adjustInto | back to summary |
---|---|
public Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have this month-of-year. This returns a temporal object of the same observable type as the input with the month-of-year changed to be the same as this.
The adjustment is equivalent to using
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended temporal = thisMonth.adjustInto(temporal); temporal = temporal.with(thisMonth); For example, given a date in May, the following are output: dateInMay.with(JANUARY); // four months earlier dateInMay.with(APRIL); // one months earlier dateInMay.with(MAY); // same date dateInMay.with(JUNE); // one month later dateInMay.with(DECEMBER); // seven months later This instance is immutable and unaffected by this method call.
|
firstDayOfYear | back to summary |
---|---|
public int firstDayOfYear(boolean leapYear) Gets the day-of-year corresponding to the first day of this month. This returns the day-of-year that this month begins on, using the leap year flag to determine the length of February.
|
firstMonthOfQuarter | back to summary |
---|---|
public Month firstMonthOfQuarter() Gets the month corresponding to the first month of this quarter. The year can be divided into four quarters. This method returns the first month of the quarter for the base month. January, February and March return January. April, May and June return April. July, August and September return July. October, November and December return October.
|
from | back to summary |
---|---|
public static Month from(TemporalAccessor temporal) Obtains an instance of
This obtains a month based on the specified temporal.
A
The conversion extracts the
This method matches the signature of the functional interface
|
get | back to summary |
---|---|
public int get(TemporalField field) Overrides default java. Gets the value of the specified field from this month-of-year as an This queries this month for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is
If the field is not a
|
getDisplayName | back to summary |
---|---|
public String getDisplayName(TextStyle style, Locale locale) Gets the textual representation, such as 'Jan' or 'December'. This returns the textual name used to identify the month-of-year, suitable for presentation to the user. The parameters control the style of the returned text and the locale.
If no textual mapping is found then the |
getLong | back to summary |
---|---|
public long getLong(TemporalField field) Implements java. Gets the value of the specified field from this month-of-year as a This queries this month for the value of the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is
If the field is not a
|
getValue | back to summary |
---|---|
public int getValue() Gets the month-of-year The values are numbered following the ISO-8601 standard, from 1 (January) to 12 (December).
|
isSupported | back to summary |
---|---|
public boolean isSupported(TemporalField field) Implements java. Checks if the specified field is supported.
This checks if this month-of-year can be queried for the specified field.
If false, then calling the
If the field is
If the field is not a
|
length | back to summary |
---|---|
public int length(boolean leapYear) Gets the length of this month in days. This takes a flag to determine whether to return the length for a leap year or not. February has 28 days in a standard year and 29 days in a leap year. April, June, September and November have 30 days. All other months have 31 days.
|
maxLength | back to summary |
---|---|
public int maxLength() Gets the maximum length of this month in days. February has a maximum length of 29 days. April, June, September and November have 30 days. All other months have 31 days.
|
minLength | back to summary |
---|---|
public int minLength() Gets the minimum length of this month in days. February has a minimum length of 28 days. April, June, September and November have 30 days. All other months have 31 days.
|
minus | back to summary |
---|---|
public Month minus(long months) Returns the month-of-year that is the specified number of months before this one. The calculation rolls around the start of the year from January to December. The specified period may be negative. This instance is immutable and unaffected by this method call.
|
of | back to summary |
---|---|
public static Month of(int month) Obtains an instance of
|
plus | back to summary |
---|---|
public Month plus(long months) Returns the month-of-year that is the specified number of months after this one. The calculation rolls around the end of the year from December to January. The specified period may be negative. This instance is immutable and unaffected by this method call.
|
query | back to summary |
---|---|
public <R> R query(TemporalQuery<R> query) Overrides default java. Queries this month-of-year using the specified query.
This queries this month-of-year using the specified query strategy object.
The
The result of this method is obtained by invoking the
|
range | back to summary |
---|---|
public ValueRange range(TemporalField field) Overrides default java. Gets the range of valid values for the specified field. The range object expresses the minimum and maximum valid values for a field. This month is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown.
If the field is
If the field is not a
|
valueOf | back to summary |
---|---|
public static Month valueOf(String name) |
values | back to summary |
---|---|
public static Month[] values() |