Pandu Abbiyuarsyah Pandu Abbiyuarsyah - 1 year ago 59
Android Question

Android : I got Error "Cannot format given Object as a Date" when converting date from JSON response

This is my code. I got error "Cannot format given Object as a Date" when trying to convert my repsonse.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");;

How to convert my repsonse
to 03-February-2017 ?

Answer Source

Try something like this:

 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 Date date3 = null;
 date3 = sdf.parse(item.getPrice().getDate());
 formatter = new SimpleDateFormat("dd-MM-yyy");
 String date1 = formatter.format(date3);;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download