Search code examples
androidtexttimeshortandroid-dateutils

Android: Is there a way to show "min" instead of "minute" with DateUtils


I'm using DateUtils to show the posted time. But is there a way to show:

"4 min ago" instead of "4 minutes ago"

        CharSequence result = DateUtils.getRelativeTimeSpanString(timestamp, Currenttime,DateUtils.SECOND_IN_MILLIS);

Solution

  • use

     getRelativeTimeSpanString (long time, 
                    long now, 
                    long minResolution, 
                    int flags)
    

    and provide as DateUtils.FORMAT_ABBREV_RELATIVE as flags.

    Accordingly to the documentation

    Can use FORMAT_ABBREV_RELATIVE flag to use abbreviated relative times, like "42 mins ago".

    E.g.

    CharSequence result = DateUtils.getRelativeTimeSpanString(timestamp, Currenttime,DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    

    should do it.