Search code examples
androiddate-formatsimpledateformatparseexception

"Unparseable date exception at offset 0" in Java


I am working on Android application in which I am trying to format my date according to my 2/1/16 5:20 AM Date.

But I am getting

java.text.ParseException: Unparseable date: "2/1/16 5:20 AM" (at offset 1).

My code is given below:

DateFormat fAfterUTC = new SimpleDateFormat("MM dd yy HH:mm aa");
Date dSelectedAfterUTC = fAfterUTC.parse("2/1/16 5:20 AM");

Solution

  • Your SimpleDateFormat is missing the /`s:

    new SimpleDateFormat("MM/dd/yy HH:mm aa")