I have the following code to convert a server returned date string to a since string.
/**
* Change date format to "since" string
* */
public static String timeSince(String dateString) {
Date date = stringToDate(dateString);
String result = (DateUtils.getRelativeTimeSpanString(date.getTime())).toString();
return result;
}
/**
* Function to convert server date string to Date
* */
public static Date stringToDate(String s){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
return df.parse(s);
} catch(ParseException e){
e.printStackTrace();
}
return null;
}
But, as an example, if I call timeSince("2016-07-04T07:21:39.575Z") I get "Jul 4, 2016" as a result, instead of something like "3 days ago" or any other period relative to now time. Any idea why ? Thx...