Reputation: 295
I am having similar problems to Unable to parse DateTime-string with AM/PM marker
I even tried the solution provided in that link but it did not help.
SimpleDateFormat timingFormat = new SimpleDateFormat("h:mm a", Locale.US);
Date l = timingFormat.parse(time);
but I keep receiving java.text.ParseException: Unparseable date: "12:34". When i enter 12:34 AM
Upvotes: 1
Views: 3341
Reputation: 24457
public static void main(String[] args) throws ParseException {
SimpleDateFormat timingFormat = new SimpleDateFormat("h:mm a", Locale.US);
Date l = timingFormat.parse("12:34 AM");
System.out.println(l.toString());
}
The above code runs fine. This means the input you've passed to the parse
method is not what you expected.
Upvotes: 1
Reputation:
Wait a second. The error says 12:34
is unparseable, not 12:34 AM
. In that case, your input method is reading the first word up to whitespace and ignoring the "AM" part of your entry. Correct your input method so that it reads the entire input stream/string, and then it should parse correctly.
Upvotes: 2