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 parse it in our day format. How do I do this? I have tried but I always have the year as 1970.
Note: My JSON format is in UNIX.
JSONObject feedObj = (JSONObject) feedArray.get(i);
FeedItem item = new FeedItem();
item.setTimeStamp(feedObj.getString("date"));
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getTimeStamp() {
return timeStamp;
}
In another class, I parse the timestamp to display it:
List<FeedItem> feedItems = ...;
FeedItem item = feedItems.get(position);
CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
Long.parseLong(item.getTimeStamp()),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
However the displayed date is always in 1970.
Using values such as 1403375851930
it appears to work as expected (it displays a contemporary date).