Am having string posting date like :
2011-03-27T09:39:01.607
and There is current date .
I want to get difference between these two dates in the form of :
2 days ago
1 minute ago etc..
depending posting date.
Am using this code to convert posting date to milliseconds:
public long Date_to_MilliSeconds(int day, int month, int year, int hour, int minute) {
Calendar c = Calendar.getInstance();
c.set(year, month, day, hour, minute, 00);
return c.getTimeInMillis();
}
this current date: long now = System.currentTimeMillis();
and to calculate difference:
String difference = (String) DateUtils.getRelativeTimeSpanString(time,now, 0);
But it returning like May 1 , 1970 or something ..
How to get the difference between posting date and current date.
The reason you get 1970 is because it is the epoch date in milli seconds. To get the actual difference use the below.
Use JodaTime