I'm trying to convert a string time stamp into something like the following:
2 Min ago. 1 Hr ago. 4 Days ago. 3 weeks ago. 5 months ago. 1 year ago.
I'm using Java's DateUtils.getRelativeTimeSpanString()
method to convert but its is showing date like 1 sep 2016. I want it to show as 6 months ago.
Here is the code :
long now = System.currentTimeMillis();
System.err.println();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.ENGLISH);
Date startDate;
try {
startDate = df.parse(userLogs.get(i).getDate());
String sds = (String) DateUtils.getRelativeTimeSpanString(startDate.getTime(),System.currentTimeMillis(),DateUtils.MINUTE_IN_MILLIS);
System.err.println(sds);
} catch (ParseException e) {
e.printStackTrace();
}
Update: I don't want to use Joda time or any other library why it is marked as duplicate I don't understand!