I have a publication date for a string, for example:
2011-03-27T09:39:01.607
and there is the current date.
I want to get the difference between these two dates in the form:
2 days ago 1 minute ago etc..
depending on the posting date.
Use this code to convert posting dates 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(); }
current date: long now = System.currentTimeMillis();
and calculate the difference:
String difference = (String) DateUtils.getRelativeTimeSpanString(time,now, 0);
But he comes back like May 1 , 1970 or something ..
How to get the difference between the posting date and the current date.
source share