java.text.ParseException: Unparseable date. "dd MMM yyyy HH:mm:ss" format

1.4k Views Asked by At

I am getting a parsing error with the following code

String time = "24 Apr 2021 11:56:44";
Date timeOnLine = new SimpleDateFormat("dd MMM yyyy HH:mm:ss").parse(time);

Exception:

java.text.ParseException: Unparseable date: "24 Apr 2021 11:56:44"

I am not sure what the problem is since the pattern seems to correspond with the string correctly.

Any advice on how to solve would be greatly appreciated!

1

There are 1 best solutions below

0
On BEST ANSWER

Try with:

String time = "24 Apr 2021 11:56:44";
Date timeOnLine = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.US).parse(time);