There is a string field in a CSV file with the following format: 2008-04-11 00:00:00
I need to convert it to date so that I can perform the following calculation in Predicate, to verify date typing errors.
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
Predicate<Client> clientBirth = p -> Period.between(LocalDate.parse(p.getBirth().replaceAll("-", "/"), formatter),LocalDate.now()).getYears() >= 100;
But it's giving an error in the first line of the CSV file.
Exception in thread "main" java.time.format.DateTimeParseException: Text '2008/04/11 00:00:00' could not be parsed at index 2
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
at java.base/java.time.LocalDate.parse(LocalDate.java:428)
at application.Program.lambda$0(Program.java:210)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:199)
at java.base/java.nio.file.FileChannelLinesSpliterator.forEachRemaining(FileChannelLinesSpliterator.java:114)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at services.CsvProcessingService.loadBirthError(CsvProcessingService.java:123)
at services.CsvProcessingService.processBirthError(CsvProcessingService.java:109)
at application.Program.main(Program.java:214)
Thanks in advance.