0

I have a String like that : String date_annonce = "2014-06-12 17:25:43";

I would like to show in my app a text like : 10 min ago or 1h ago or 2d ago

It represent the difference from date_annonce and actual date.

How can i do this ?

wawanopoulos
  • 9,614
  • 31
  • 111
  • 166

2 Answers2

3

see this DateUtil method

getRelativeDateTimeString

String relativeString = getRelativeDateTimeString (this, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,DateUtils.WEEK_IN_MILLIS, 0));
MilapTank
  • 9,988
  • 7
  • 38
  • 53
0

you have to subtract System.currentTimeMillis() from data_annonce in milliseconds. To convert it milliseconds you can use SimpleDateFormat to get a Date object from the string.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • The OP would also have to do some rounding to the nearest time component (minute, hour, day, week, etc.) to create a nice representation. – Chnoch Jun 20 '14 at 11:34