--12-03.
MonthDay is an immutable date-time object that represents the combination
of a month and day-of-month. Any field that can be derived from a month and day,
such as quarter-of-year, can be obtained.
This class does not store or represent a year, time or time-zone.
For example, the value "December 3rd" can be stored in a MonthDay.
Since a MonthDay does not possess a year, the leap day of
February 29th is considered valid.
This class implements TemporalAccessor rather than Temporal.
This is because it is not possible to define whether February 29th is valid or not
without external information, preventing the implementation of plus/minus.
Related to this, MonthDay only provides access to query and set the fields
MONTH_OF_YEAR and DAY_OF_MONTH.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.
This is a value-based
class; programmers should treat instances that are
equal as interchangeable and should not
use instances for synchronization, or unpredictable behavior may
occur. For example, in a future release, synchronization may fail.
The equals method should be used for comparisons.
Implementation Specification
This class is immutable and thread-safe.
| Modifier and Type | Field and Description |
|---|---|
| private final transient byte | |
| private final transient byte | |
| private static final DateTimeFormatter | PARSER
Parser. |
| private static final ObjectStreamField[] | serialPersistentFields
For backward compatibility of the serialized |
| private static final long | serialVersionUID
Serialization version. |
| Access | Constructor and Description |
|---|---|
| private | MonthDay(int
the month-of-year to represent, validated from 1 to 12 month, int the day-of-month to represent, validated from 1 to 29-31 dayOfMonth)Constructor, previously validated. |
| 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-day. |
| public LocalDate | Returns: the local date formed from this month-day and the specified year, not nullthe year to use, from MIN_YEAR to MAX_YEAR year)Combines this month-day with a year to create a |
| public int | Returns: the comparator value, that is less than zero if this is beforeother,
zero if they are equal, greater than zero if this is after otherthe other month-day to compare to, not null other)Implements java. Compares this month-day to another month-day. |
| public boolean | Returns: true if this is equal to the other month-daythe object to check, null returns false obj)Overrides java. Checks if this month-day is equal to another month-day. |
| public String | Returns: the formatted month-day string, not nullthe formatter to use, not null formatter)Formats this month-day using the specified formatter. |
| public static MonthDay | Returns: the month-day, not nullthe temporal object to convert, not null temporal)Obtains an instance of |
| public int | Returns: the value for the fieldthe field to get, not null field)Overrides default java. Gets the value of the specified field from this month-day as an |
| public int | |
| 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-day as a |
| public Month | |
| public int | |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this month-day. |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if the field is supported on this month-day, false if notthe field to check, null returns false field)Implements java. Checks if the specified field is supported. |
| public boolean | Returns: true if the year is valid for this month-daythe year to validate year)Checks if the year is valid for this month-day. |
| public static MonthDay | Returns: the current month-day using the system clock and default time-zone, not nullObtains the current month-day from the system clock in the default time-zone. |
| public static MonthDay | |
| public static MonthDay | |
| public static MonthDay | |
| public static MonthDay | Returns: the month-day, not nullthe month-of-year to represent, from 1 (January) to 12 (December) month, int the day-of-month to represent, from 1 to 31 dayOfMonth)Obtains an instance of |
| public static MonthDay | Returns: the parsed month-day, not nullthe text to parse such as "--12-03", not null text)Obtains an instance of |
| public static MonthDay | Returns: the parsed month-day, not nullthe text to parse, not null text, DateTimeFormatter the formatter to use, not null formatter)Obtains an instance of |
| 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-day 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. |
| pack-priv static MonthDay | |
| private void | |
| public String | Returns: a string representation of this month-day, not nullOverrides java. Outputs this month-day as a |
| public MonthDay | |
| public MonthDay | Returns: aMonthDay based on this month-day with the requested day, not nullthe day-of-month to set in the return month-day, from 1 to 31 dayOfMonth)Returns a copy of this |
| public MonthDay | Returns: aMonthDay based on this month-day with the requested month, not nullthe month-of-year to set in the returned month-day, from 1 (January) to 12 (December) month)Returns a copy of this |
| pack-priv void | |
| private Object | Returns: the instance ofSer, not nullWrites the object using a dedicated serialized form. |
| day | back to summary |
|---|---|
| private final transient byte day | |
| month | back to summary |
|---|---|
| private final transient byte month | |
| PARSER | back to summary |
|---|---|
| private static final DateTimeFormatter PARSER Parser. | |
| serialPersistentFields | back to summary |
|---|---|
| private static final ObjectStreamField[] serialPersistentFields For backward compatibility of the serialized
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| MonthDay | back to summary |
|---|---|
| private MonthDay(int month, int dayOfMonth) Constructor, previously validated.
| |
| adjustInto | back to summary |
|---|---|
| public Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have this month-day. This returns a temporal object of the same observable type as the input with the month and day-of-month 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 = thisMonthDay.adjustInto(temporal); temporal = temporal.with(thisMonthDay); This instance is immutable and unaffected by this method call.
| |
| atYear | back to summary |
|---|---|
| public LocalDate atYear(int year) Combines this month-day with a year to create a
This returns a A month-day of February 29th will be adjusted to February 28th in the resulting date if the year is not a leap year. This instance is immutable and unaffected by this method call.
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(MonthDay other) Implements java. Compares this month-day to another month-day.
The comparison is based first on value of the month, then on the value of the day.
It is "consistent with equals", as defined by | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Checks if this month-day is equal to another month-day. The comparison is based on the time-line position of the month-day within a year. | |
| format | back to summary |
|---|---|
| public String format(DateTimeFormatter formatter) Formats this month-day using the specified formatter. This month-day will be passed to the formatter to produce a string.
| |
| from | back to summary |
|---|---|
| public static MonthDay from(TemporalAccessor temporal) Obtains an instance of
This obtains a month-day 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-day as an This queries this month-day 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 a
If the field is not a
| |
| getDayOfMonth | back to summary |
|---|---|
| public int getDayOfMonth() Gets the day-of-month field.
This method returns the primitive
| |
| getLong | back to summary |
|---|---|
| public long getLong(TemporalField field) Implements java. Gets the value of the specified field from this month-day as a This queries this month-day 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 a
If the field is not a
| |
| getMonth | back to summary |
|---|---|
| public Month getMonth() Gets the month-of-year field using the
This method returns the enum
| |
| getMonthValue | back to summary |
|---|---|
| public int getMonthValue() Gets the month-of-year field from 1 to 12.
This method returns the month as an
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this month-day.
| |
| isAfter | back to summary |
|---|---|
| public boolean isAfter(MonthDay other) Checks if this month-day is after the specified month-day.
| |
| isBefore | back to summary |
|---|---|
| public boolean isBefore(MonthDay other) Checks if this month-day is before the specified month-day.
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(TemporalField field) Implements java. Checks if the specified field is supported.
This checks if this month-day can be queried for the specified field.
If false, then calling the
If the field is a
ChronoField instances will return false.
If the field is not a
| |
| isValidYear | back to summary |
|---|---|
| public boolean isValidYear(int year) Checks if the year is valid for this month-day. This method checks whether this month and day and the input year form a valid date. This can only return false for February 29th.
| |
| now | back to summary |
|---|---|
| public static MonthDay now() Obtains the current month-day from the system clock in the default time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
| |
| now | back to summary |
|---|---|
| public static MonthDay now(ZoneId zone) Obtains the current month-day from the system clock in the specified time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded. | |
| now | back to summary |
|---|---|
| public static MonthDay now(Clock clock) Obtains the current month-day from the specified clock.
This will query the specified clock to obtain the current month-day.
Using this method allows the use of an alternate clock for testing.
The alternate clock may be introduced using | |
| of | back to summary |
|---|---|
| public static MonthDay of(Month month, int dayOfMonth) Obtains an instance of The day-of-month must be valid for the month within a leap year. Hence, for February, day 29 is valid. For example, passing in April and day 31 will throw an exception, as there can never be April 31st in any year. By contrast, passing in February 29th is permitted, as that month-day can sometimes be valid.
| |
| of | back to summary |
|---|---|
| public static MonthDay of(int month, int dayOfMonth) Obtains an instance of The day-of-month must be valid for the month within a leap year. Hence, for month 2 (February), day 29 is valid. For example, passing in month 4 (April) and day 31 will throw an exception, as there can never be April 31st in any year. By contrast, passing in February 29th is permitted, as that month-day can sometimes be valid.
| |
| parse | back to summary |
|---|---|
| public static MonthDay parse(CharSequence text) Obtains an instance of
The string must represent a valid month-day.
The format is
| |
| parse | back to summary |
|---|---|
| public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) Obtains an instance of The text is parsed using the formatter, returning a month-day.
| |
| query | back to summary |
|---|---|
| public <R> R query(TemporalQuery<R> query) Overrides default java. Queries this month-day using the specified query.
This queries this month-day 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-day 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 a
If the field is not a
| |
| readExternal | back to summary |
|---|---|
| pack-priv static MonthDay readExternal(DataInput in) throws IOException | |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this month-day as a
The output will be in the format | |
| with | back to summary |
|---|---|
| public MonthDay with(Month month) Returns a copy of this This returns a month-day with the specified month. If the day-of-month is invalid for the specified month, the day will be adjusted to the last valid day-of-month. This instance is immutable and unaffected by this method call. | |
| withDayOfMonth | back to summary |
|---|---|
| public MonthDay withDayOfMonth(int dayOfMonth) Returns a copy of this This returns a month-day with the specified day-of-month. If the day-of-month is invalid for the month, an exception is thrown. This instance is immutable and unaffected by this method call.
| |
| withMonth | back to summary |
|---|---|
| public MonthDay withMonth(int month) Returns a copy of this This returns a month-day with the specified month. If the day-of-month is invalid for the specified month, the day will be adjusted to the last valid day-of-month. This instance is immutable and unaffected by this method call.
| |
| writeExternal | back to summary |
|---|---|
| pack-priv void writeExternal(DataOutput out) throws IOException | |
| writeReplace | back to summary |
|---|---|
| private Object writeReplace() Writes the object using a dedicated serialized form. | |