James Berners
James Berners

Reputation: 103

Error while parsing string of time to calendar

Im using the following code to convert from string with value 09:10:06 but in the cal set time I got exception: Unparseable date: "09:19:06" how can I overcome this issue.

DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal  = Calendar.getInstance();
try {
cal.setTime(df.parse(memberValue));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Upvotes: 0

Views: 94

Answers (2)

Jigar Joshi
Jigar Joshi

Reputation: 240898

pattern should be dd:MM:yyyy for 09:10:06 input

Upvotes: 0

Tudor Zgureanu
Tudor Zgureanu

Reputation: 725

The problem is you're trying to parse an hour with a wrong pattern. Here is the fix.

DateFormat df = new SimpleDateFormat("HH:mm:ss");

Upvotes: 1

Related Questions