I have a JSON array received from my server. I obtain a date as a timestamp String – for example, [{\"date\": \"1418056895\", ... }]
– and I need to
If you are parsing JSON correctly,
feedObj.getString("date");
holds your date. You are reading date as String. You have to convert it to long.
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
Long timestamp = Long.parseLong("1418056895"); //Long.parseLong(feedObj.getString("date"));
cal.setTimeInMillis(timestamp * 1000L);
DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // what ever format you need.
System.out.println(format.format(cal.getTime())); // this will be in MM/dd/yyyy
//item.setTimeStamp(format.format(cal.getTime()));
}
you can also use feedObj.getLong("date"); to get Date in long format directly, but it depends on which JSON library you using.