I try to convert an input type String into LocalDate with format "MMM/dd/yyyy", but when I enter input, it throws an exception:
Exception in thread "main" java.time.format.DateTimeParseException: Text 'DEC/12/1999' could not be parsed at index 0
Here is my code:
Scanner sc = new Scanner(System.in);
DateTimeFormatter format1 = DateTimeFormatter.ofPattern("MMM/dd/yyyy");
System.out.print("Please enter the first date: ");
LocalDate firstDate = LocalDate.parse(sc.nextLine(), format1);
System.out.print("Please enter the second date: ");
System.out.println(firstDate);
How can I fix this?