Jacek Kwiecień
Jacek Kwiecień

Reputation: 12649

How to always get minutes from DateUtils.getRelativeTimeSpanString?

I need to display text like "2 hours, 31 minutes ago". I'm not attached to the format, it can be different. I wonder if I could do it with android.text.format.DateUtils.

So far I only partially succeeded with this:

val timePart = DateUtils.getRelativeTimeSpanString(
                    pastDateMillis, // for testing purposes I hardcoded it to now - 2:31
                    nowMillis,
                    DateUtils.MINUTE_IN_MILLIS,
                    DateUtils.FORMAT_ABBREV_RELATIVE
                )

This function properly displays minutes but only before an hour passes. When it's like 1:51 it will be always "1 hour ago", and changes to "2 hours ago" at 2:00

Can this be tweaked or do I have to use something different?

Upvotes: 4

Views: 133

Answers (0)

Related Questions