I have a problem with reading data from a .txt text file. The point is that I have to load data on the date of the action, which is sometimes written in the format 2020-12-12 and 2022-7-9. To take further action on this data, I would like the program to read it as a LocalDate type, to do this I created a formatter and a place where ko is applied:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(dateOfVisit,formatter);
I get the error "DateTimeParseExceptionText '2022-1-25' could not be parsed at index 5'.
How could I make this pattern more flexible?
The code is structured correctly and I know that the error lies in what I added above, how would you change it?