I am trying to convert a string date format to another date format(dd-MMM-yyyy) using LocalDate.
String date = "2018-04-16";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy", Locale.US);
LocalDate localDate = LocalDate.parse(date, formatter);
I tried this code with and without the Locale.US in the DateTimeFormatter object. Either way it is returning this exception instead:
java.time.format.DateTimeParseException: Text '2018-04-16' could not be parsed at index 2
Is there a way I can handle this date conversion using LocalDate or should I use SimpleDateFormat?