documentation for YearMonth
对如何处理此问题没有任何建议。
目前我正在使用以下方法检查LocalDate
是否属于YearMonth
,其中date
和yearMonth
分别是这些值:< / p>
YearMonth lastDayOfPreviousMonth = yearMonth.atDay(1).minusDay(1);
YearMonth firstDayOfNextMonth = yearMonth.atEndOfMonth().plusDays(1);
return date.isAfter(lastDayOfPreviousMonth)
&& date.isBefore(firstDayOfNextMonth);
有没有更清洁或内置的方法来做到这一点?
答案 0 :(得分:7)
检查LocalDate
是否属于YearMonth
范围的更清晰的方法是获取YearMonth
的{{1}},然后将其与原始版本进行比较date
:
yearMonth