7

I'm working on getting Json objects from a service to a List View in Android... the date format looks like this "/Date(1354222800000+0300)/" ... how can I change it to a readable format?

for (int i = 0; i < json.length(); i++) {

    HashMap<String, String> map = new HashMap<String, String>();
    JSONObject e = json.getJSONObject(i);
    map.put("mDate", "" + e.getString("mDate"));
    mylist.add(map);

}

2 Answers2

0

This is the MS JSON date format.

Use:

var myDate = new Date(parseInt(String(dateString).substr(6)));
bnieland
  • 6,047
  • 4
  • 40
  • 66
0
    String mDate = getFormattedDate(e.getString("JSON OBJECT"));

    private String getFormattedDate(String stringDate) throws JSONException {
    String strDate = stringDate.replace("/Date(", "").replace(")/", "");

    strDate = strDate.substring(0, strDate.indexOf("+"));
    Long longDate = Long.parseLong(strDate, 10);
    Date mDate = new Date(longDate);

    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
    String formattedDate = sdf.format(mDate);

    return formattedDate;
}