Ragesh Pikalmunde
Ragesh Pikalmunde

Reputation: 1403

Unparsable Date exception?

I would appreciate any help with finding bug for this exception:

java.text.ParseException: Unparseable date: "2017-11-28-12:53 PM"

and following code :

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-hh:mm a");

String TimeStamp = adptAllTests.get(i).getDateString()+""+adptAllTests.get(i).getStartTime();
Long startTimeStamp = format.parse(TimeStamp).getTime();

it throws an exception while parsing TimeStamp to startTimeStamp

Upvotes: 0

Views: 2155

Answers (1)

SpiritCrusher
SpiritCrusher

Reputation: 21053

You are using wrong format:

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH:mm a");

It should be:

 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-hh:mm a");

h represents Hour in am/pm (1-12)

H represents Hour in day (0-23)

In your case i think you forgot to add a "-" between date and time . change the following line as below.

String TimeStamp = adptAllTests.get(i).getDateString()+"-"+adptAllTests.get(i).getStartTime();

Upvotes: 4

Related Questions