DateUtils.getRelativeTimeSpanString returns the difference in time but result includes the current time

237 views Asked by At
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.

2

There are 2 answers

1
johnson On
string.substring(0, string.indexOf(",") 

that solved it

2
James On

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());