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); } 
3
  • is there on documentation what this format means? [+0300 quite sure means GMT + 3h] Commented Dec 30, 2012 at 16:48
  • use "substring" to extract the datetimemillis (always 13 numbers) or use regexp. Commented Dec 30, 2012 at 16:59
  • i found this answer stackoverflow.com/questions/7103792/… Commented Dec 30, 2012 at 18:00

2 Answers 2

0

This is the MS JSON date format.

Use:

var myDate = new Date(parseInt(String(dateString).substr(6))); 
Sign up to request clarification or add additional context in comments.

1 Comment

yeah, i know it in java script :) but im new in android development and i want to change the format into java... thanks for your answer
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; } 

2 Comments

This is how i found a solution to format a JSON Date to a readable format, :) :) :)
JSONObject e = json.getJSONObject(i);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.