String转LocalDateTime报错
一 问题描述
根据网上的办法,将String转成LocalDateTime,出现下面情况:
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime ldt = LocalDateTime.parse("20191201",df);
LocalDateTime ldt2 = LocalDateTime.parse("20191222", df);
二 解决办法
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDateTime ldt = LocalDateTime.from(LocalDate.parse("20191201",df).atStartOfDay());
LocalDateTime ldt2 = LocalDateTime.from(LocalDate.parse("20191222",df).atStartOfDay());