سؤال

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();
}
هل كانت مفيدة؟

المحلول

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");

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top