这个问题在这里已有答案:
我有一个字符串限制一个月和一年前:2019-02
我需要转换为两个LocalDateTime
。我需要第一天和02月的最后一天。
使用YearMonth
类:
YearMonth yearMonth = YearMonth.parse("2019-02");
LocalDate startDate = yearMonth.atDay(1); // 2019-02-01
LocalDate endDate = yearMonth.atEndOfMonth(); // 2019-02-28
然后你可以转换为LocalDateTime
,例如如果你需要一天的开始时间:
LocalDateTime startDayTime = startDate.atStartOfDay(); // 2019-02-01T00:00