Am having string posting date like :
2011-03-27T09:39:01.607
and There is current date .
I want to get difference between these tw
Try the following method that I used in one of my applications:
/**
* Returns difference between time and current time as string like:
* "23 mins ago" relative to current time.
* @param time - The time to compare with current time in yyyy-MM-dd HH:mm:ss format
* @param currentTime - Present time in yyyy-MM-dd HH:mm:ss format
* @return String - The time difference as relative text(e.g. 23 mins ago)
* @throws ParseException
*/
private String getTimeDiff(String time, String currentTime) throws ParseException
{
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentDate = (Date)formatter.parse(currentTime);
Date oldDate = (Date)formatter.parse(time);
long oldMillis = oldDate.getTime();
long currentMillis = currentDate.getTime();
return DateUtils.getRelativeTimeSpanString(oldMillis, currentMillis, 0).toString();
}