DayOfMonth is an immutable date-time object that represents a day-of-month.
It is a type-safe way of representing a day-of-month in an application.
Any field that can be derived from a day-of-month can be obtained.
This class does not store or represent a year, month, time or time-zone.
For example, the value "21" can be stored in a DayOfMonth and
would represent the 21st day of any month.
This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.
| Modifier and Type | Field and Description |
|---|---|
| private final int | day
The day-of-month being represented, from 1 to 31. |
| private static final long | serialVersionUID
Serialization version. |
| private static final DayOfMonth[] | VALUES
Cache of singleton instances. |
| 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 day-of-month. |
| public MonthDay | |
| public MonthDay | Returns: the year-month formed from this year and the specified month, not nullthe month-of-year to use, from 1 (January) to 12 (December) month)Combines this day-of-month with a month to create a |
| public LocalDate | Returns: the local date formed from this year and the specified year-month, not nullthe year-month to use, not null yearMonth)Combines this day-of-month with a year-month to create a |
| public int | Returns: the comparator value, negative if less, positive if greaterthe other day-of-month instance, not null other)Implements java. Compares this day-of-month to another. |
| public boolean | Returns: true if the day-of-month is the samethe other day-of-month instance, null returns false obj)Overrides java. Checks if this day-of-month is equal to another day-of-month. |
| public static DayOfMonth | Returns: the day-of-month, 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 day-of-month as an |
| 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 day-of-month as a |
| public int | |
| public int | Returns: a suitable hash codeOverrides java. A hash code for this day-of-month. |
| public boolean | Returns: true if the field is supported on this day-of-month, 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 and month are valid for this daythe year month to validate, null returns false yearMonth)Checks if the year-month is valid for this year. |
| public static DayOfMonth | Returns: the current day-of-month using the system clock and default time-zone, not nullObtains the current day-of-month from the system clock in the default time-zone. |
| public static DayOfMonth | |
| public static DayOfMonth | |
| public static DayOfMonth | Returns: the day-of-month, not nullthe day-of-month to represent, from 1 to 31 dayOfMonth)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 day-of-month 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. |
| private Object | |
| public String | Returns: a string representation of this day-of-month, not nullOverrides java. Outputs this day-of-month as a |
| day | back to summary |
|---|---|
| private final int day The day-of-month being represented, from 1 to 31. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| VALUES | back to summary |
|---|---|
| private static final DayOfMonth[] VALUES Cache of singleton instances. | |
| DayOfMonth | back to summary |
|---|---|
| private DayOfMonth(int dayOfMonth) Constructor.
| |
| adjustInto | back to summary |
|---|---|
| public Temporal adjustInto(Temporal temporal) Implements java. Adjusts the specified temporal object to have this day-of-month. This returns a temporal object of the same observable type as the input with the 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 = thisDay.adjustInto(temporal); temporal = temporal.with(thisDay); This instance is immutable and unaffected by this method call.
| |
| atMonth | back to summary |
|---|---|
| public MonthDay atMonth(Month month) Combines this day-of-month with a month to create a
This returns a This method can be used as part of a chain to produce a date: LocalDate date = day.atMonth(month).atYear(year); If this day-of-month is invalid for the month then it will be changed to the last valid date for the month. | |
| atMonth | back to summary |
|---|---|
| public MonthDay atMonth(int month) Combines this day-of-month with a month to create a
This returns a This method can be used as part of a chain to produce a date: LocalDate date = day.atMonth(month).atYear(year); If this day-of-month is invalid for the month then it will be changed to the last valid date for the month.
| |
| atYearMonth | back to summary |
|---|---|
| public LocalDate atYearMonth(YearMonth yearMonth) Combines this day-of-month with a year-month to create a
This returns a If this day-of-month is invalid for the year-month then it will be changed to the last valid date for the month. | |
| compareTo | back to summary |
|---|---|
| public int compareTo(DayOfMonth other) Implements java. Compares this day-of-month to another.
The comparison is based 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 day-of-month is equal to another day-of-month. | |
| from | back to summary |
|---|---|
| public static DayOfMonth from(TemporalAccessor temporal) Obtains an instance of
This obtains a day-of-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 day-of-month as an This queries this day-of-month for the value for 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
| |
| getLong | back to summary |
|---|---|
| public long getLong(TemporalField field) Implements java. Gets the value of the specified field from this day-of-month as a This queries this day-of-month for the value for 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
| |
| getValue | back to summary |
|---|---|
| public int getValue() Gets the day-of-month value.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. A hash code for this day-of-month.
| |
| isSupported | back to summary |
|---|---|
| public boolean isSupported(TemporalField field) Implements java. Checks if the specified field is supported.
This checks if this day-of-month 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
| |
| isValidYearMonth | back to summary |
|---|---|
| public boolean isValidYearMonth(YearMonth yearMonth) Checks if the year-month is valid for this year. This method checks whether this day and the input year and month form a valid date.
| |
| now | back to summary |
|---|---|
| public static DayOfMonth now() Obtains the current day-of-month 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 DayOfMonth now(ZoneId zone) Obtains the current day-of-month 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 DayOfMonth now(Clock clock) Obtains the current day-of-month from the specified clock.
This will query the specified clock to obtain the current day-of-month.
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 DayOfMonth of(int dayOfMonth) Obtains an instance of A day-of-month object represents one of the 31 days of the month, from 1 to 31.
| |
| query | back to summary |
|---|---|
| public <R> R query(TemporalQuery<R> query) Overrides default java. Queries this day-of-month using the specified query.
This queries this day-of-month 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 day-of-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 a
If the field is not a
| |
| readResolve | back to summary |
|---|---|
| private Object readResolve() Validates the input.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Outputs this day-of-month as a | |