答案 1
只需使用 , 和 :withDayOfMonth
lengthOfMonth()
LocalDate initial = LocalDate.of(2014, 2, 13);
LocalDate start = initial.withDayOfMonth(1);
LocalDate end = initial.withDayOfMonth(initial.getMonth().length(initial.isLeapYear()));
答案 2
该 API 旨在支持与业务需求紧密匹配的解决方案
import static java.time.temporal.TemporalAdjusters.*;
LocalDate initial = LocalDate.of(2014, 2, 13);
LocalDate start = initial.with(firstDayOfMonth());
LocalDate end = initial.with(lastDayOfMonth());
但是,Jon的解决方案也很好。
推荐
标签