0
CharSequence string = DateUtils.getRelativeDateTimeString(getActivity(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
            DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);

Result is "0 min ago, 00:19" i only need the "0 min ago", how do i get rid of the curent time added to it.

johnson
  • 111
  • 11

2 Answers2

-1

You can do it by doing:

CharSequence string = (DateUtils.getRelativeDateTimeString(getActivity(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
        DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE)).subSequence(string.length() - 5, string.length());
James
  • 1,928
  • 3
  • 13
  • 30
  • I'm not calling the method on a fixed time but on different set of time. Sometimes the difference can be "12 min ago" which makes the string length increase. Can't I return only the difference as result without the current time added to it, or what should I do? – johnson Aug 05 '18 at 23:49
  • I have accounted for that by calling the function `string.length()` which will get the string length dynamically. Have you tried it? I also updated my answer to be one line of code. – James Aug 06 '18 at 00:00
-1
string.substring(0, string.indexOf(",") 

that solved it

johnson
  • 111
  • 11
  • That would actually be incorrect because it gives you an extra space and returns a string. – James Aug 06 '18 at 12:44