I try to parse string do the Date format, but get Unparserable exception:
public void roundTest() throws ParseException {
String pattern = "MMM dd, yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String from = "Jul 01, 2021";
Date result = sdf.parse(from);
}
The same for java.time
package:
public void roundTest() throws ParseException {
String from = "Jul 01, 2021";
String pattern = "MMM dd, yyyy";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
System.out.println(LocalDate.parse(from, formatter));
}
Error: "java.time.format.DateTimeParseException: Text 'Jul 01, 2021' could not be parsed at index 0"
Where the error?