Java 如何找到YearMonth等于或在当前月份之后?
我想找到月份等于或在当前的YearMonth之后Java 如何找到YearMonth等于或在当前月份之后?,java,datetime,date,Java,Datetime,Date,我想找到月份等于或在当前的YearMonth之后 final YearMonth yearMonth = YearMonth.of(2020, 8); final boolean after = yearMonth.isAfter(YearMonth.now()); 这里的当前月份是8月8日,我尝试了isAfter,它返回false 我还想为本月返回true YearMonth本身是否有任何方法?您可以使用该方法的否定: 毕竟,一个YearMonth可以在另一个YearMonth之前、之后或
final YearMonth yearMonth = YearMonth.of(2020, 8);
final boolean after = yearMonth.isAfter(YearMonth.now());
这里的当前月份是8月8日,我尝试了isAfter,它返回false
我还想为本月返回true
YearMonth本身是否有任何方法?您可以使用该方法的否定:
毕竟,一个YearMonth可以在另一个YearMonth之前、之后或等于另一个YearMonth,因此如果一个YearMonth在另一个YearMonth之前是而不是,那么它必须在它之前或之后。嗯,我很确定一定有人错过了点击,顺便说一下,不是我。噢,否决票不见了。除了返回
yearMonth=yearMonth.of(2019,8)的true
代码>这完全是错误的,因为它只是比较月份,而不是年份。
return yearMonth.getMonth().getValue()>= YearMonth.now().getMonth().getValue();
return yearMonth.getMonth().getValue()>= YearMonth.now().getMonth().getValue();