I have a problem here, the format of the date was given (dd-MM-YYYY) and it's a not a good format (I know) but that was the raw data, and I can't parse the string using SimpleDateFormat
class, it gives an Error
java.text.ParseException: Unparseable date: "27-08-2019"
And I also use the DateTimeFormatter
but again it can't be parse, this is the error.
java.time.format.DateTimeParseException: Text '19-08-2019' could not be parsed at index 0
So my working option is to format first the String
so that the Date Formatter can parse the string date, but if there are other option to minimize manipulation of data in String
format will be nice. Thanks.
EDIT
Sorry for not posting the code.
This the code using the SimpleDateFormat
String string = "08-27-2019";
DateFormat format = new SimpleDateFormat("yyyy/MM/dd", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date);
And here using the DateTimeFormatter
and LocalDate
.
String string = "08-27-2019";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd", Locale.ENGLISH);
LocalDate date = LocalDate.parse(string, formatter);
System.out.println(date);