Pandu Abbiyuarsyah Pandu Abbiyuarsyah - 1 year ago 73
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");

holder.date.setText(sdf.format(item.getPrice().getDate()));


How to convert my repsonse
2017-02-03T11:44:52.6152Z
to 03-February-2017 ?
Thanks

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);
 holder.date.setText(date1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download