If the String date does not contain the values โโof hours, minutes, etc., you cannot directly convert this to LocalDateTime . You can convert it only to LocalDate , because the line represents only the components of the year, month and date, this will be the right thing.
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd"); LocalDate ld = LocalDate.parse("20180306", dtf);
In any case, you can convert this to LocalDateTime .
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd"); LocalDate ld = LocalDate.parse("20180306", dtf); LocalDateTime ldt = LocalDateTime.of(ld, LocalTime.of(0,0)); // 2018-03-06T00:00
prime Mar 12 '18 at 9:38 2018-03-12 09:38
source share