1

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!

2
  • 3
    Is "Apr" actually "April" in the default locale of wherever this code is running on? Commented Apr 24, 2021 at 11:24
  • I recommend you don’t use SimpleDateFormat and Date. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use LocalDateTime and DateTimeFormatter, both from java.time, the modern Java date and time API. Commented Apr 24, 2021 at 12:11

1 Answer 1

3

Try with:

String time = "24 Apr 2021 11:56:44";
Date timeOnLine = new SimpleDateFormat("dd MMM yyyy HH:mm:ss", Locale.US).parse(time);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.