Search code examples
javasimpledateformatparseexception

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


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!


Solution

  • Try with:

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