Class DayOfMonth
java.lang.Object
cloud.opencode.base.date.extra.DayOfMonth
- All Implemented Interfaces:
Serializable, Comparable<DayOfMonth>, TemporalAccessor, TemporalAdjuster
public final class DayOfMonth
extends Object
implements TemporalAccessor, TemporalAdjuster, Comparable<DayOfMonth>, Serializable
DayOfMonth class representing a day within a month (1-31)
月份中的天,表示月份中的一天(1-31)
This class represents a day-of-month value, independent of any particular month or year. When combined with a specific month/year, the validity of the day-of-month is checked.
此类表示月份中的天值,独立于任何特定的月份或年份。 当与特定月份/年份组合时,会检查日期的有效性。
Features | 主要功能:
- Day-of-month representation (1-31) - 月中天数表示(1-31)
- Validation for specific year-months - 特定年月验证
- Combine with YearMonth to create LocalDate - 与YearMonth组合创建LocalDate
- TemporalAccessor and TemporalAdjuster implementations - 实现TemporalAccessor和TemporalAdjuster
Usage Examples | 使用示例:
DayOfMonth day = DayOfMonth.of(15);
DayOfMonth first = DayOfMonth.first();
boolean valid = day.isValidFor(YearMonth.of(2024, 2)); // true for day 15 in Feb 2024
LocalDate date = day.atYearMonth(YearMonth.of(2024, 3)); // 2024-03-15
Security | 安全性:
- Thread-safe: Yes (immutable, cached instances) - 线程安全: 是(不可变,缓存实例)
- Null-safe: Yes (with explicit null checks) - 空值安全: 是(有明确的空值检查)
- Since:
- JDK 25, opencode-base-date V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionadjustInto(Temporal temporal) atYearMonth(int year, int month) Combines this day with year and month to create a LocalDate 将此天与年和月组合创建LocalDateatYearMonth(int year, Month month) Combines this day with year and Month to create a LocalDate 将此天与年和Month组合创建LocalDateatYearMonth(YearMonth yearMonth) Combines this day with a YearMonth to create a LocalDate 将此天与YearMonth组合创建LocalDateintcompareTo(DayOfMonth other) booleanstatic DayOfMonthfirst()Gets the first day of month (1) 获取月份的第一天(1)static DayOfMonthfrom(TemporalAccessor temporal) Gets a DayOfMonth from a TemporalAccessor 从TemporalAccessor获取DayOfMonthlonggetLong(TemporalField field) intgetValue()Gets the day-of-month value (1-31) 获取月份中的天值(1-31)inthashCode()booleanisFirst()Checks if this is the first day of month 检查是否为月份的第一天booleanChecks if this could be the last day of any month 检查是否可能是某月的最后一天booleanisSupported(TemporalField field) booleanisValidFor(Month month, boolean leapYear) Checks if this day is valid for the given month in a leap year 检查此天在闰年的给定月份中是否有效booleanisValidFor(YearMonth yearMonth) Checks if this day is valid for the given YearMonth 检查此天在给定YearMonth中是否有效static DayOfMonthnow()Gets the current day of month 获取当前月份中的天static DayOfMonthof(int dayOfMonth) Creates a DayOfMonth from a value (1-31) 从值(1-31)创建DayOfMonthstatic TemporalQuery<DayOfMonth> query()Gets a query for extracting DayOfMonth from a temporal 获取从时间对象提取DayOfMonth的查询range(TemporalField field) toString()Methods inherited from interface TemporalAccessor
get, query
-
Method Details
-
of
Creates a DayOfMonth from a value (1-31) 从值(1-31)创建DayOfMonth- Parameters:
dayOfMonth- the day of month (1-31) | 月份中的天(1-31)- Returns:
- the DayOfMonth | DayOfMonth实例
- Throws:
OpenDateException- if the value is out of range | 如果值超出范围则抛出异常
-
first
-
from
Gets a DayOfMonth from a TemporalAccessor 从TemporalAccessor获取DayOfMonth- Parameters:
temporal- the temporal accessor | 时间访问器- Returns:
- the DayOfMonth | DayOfMonth实例
-
now
Gets the current day of month 获取当前月份中的天- Returns:
- the current DayOfMonth | 当前的DayOfMonth
-
getValue
public int getValue()Gets the day-of-month value (1-31) 获取月份中的天值(1-31)- Returns:
- the day value | 天值
-
isValidFor
Checks if this day is valid for the given YearMonth 检查此天在给定YearMonth中是否有效- Parameters:
yearMonth- the year-month | 年月- Returns:
- true if valid | 如果有效返回true
-
isValidFor
Checks if this day is valid for the given month in a leap year 检查此天在闰年的给定月份中是否有效- Parameters:
month- the month | 月份leapYear- whether it's a leap year | 是否为闰年- Returns:
- true if valid | 如果有效返回true
-
isFirst
public boolean isFirst()Checks if this is the first day of month 检查是否为月份的第一天- Returns:
- true if day is 1 | 如果是第1天返回true
-
isPossibleLastDay
public boolean isPossibleLastDay()Checks if this could be the last day of any month 检查是否可能是某月的最后一天- Returns:
- true if day is 28, 29, 30, or 31 | 如果天数是28、29、30或31返回true
-
atYearMonth
Combines this day with a YearMonth to create a LocalDate 将此天与YearMonth组合创建LocalDate- Parameters:
yearMonth- the year-month | 年月- Returns:
- the resulting date | 结果日期
- Throws:
OpenDateException- if this day is not valid for the given month | 如果此天在给定月份无效则抛出异常
-
atYearMonth
Combines this day with year and month to create a LocalDate 将此天与年和月组合创建LocalDate- Parameters:
year- the year | 年month- the month | 月- Returns:
- the resulting date | 结果日期
-
atYearMonth
-
isSupported
- Specified by:
isSupportedin interfaceTemporalAccessor
-
getLong
- Specified by:
getLongin interfaceTemporalAccessor
-
range
- Specified by:
rangein interfaceTemporalAccessor
-
adjustInto
- Specified by:
adjustIntoin interfaceTemporalAdjuster
-
query
Gets a query for extracting DayOfMonth from a temporal 获取从时间对象提取DayOfMonth的查询- Returns:
- the query | 查询
-
compareTo
- Specified by:
compareToin interfaceComparable<DayOfMonth>
-
equals
-
hashCode
-
toString
-