Reputation: 2059
I have code like this
DateUtils.getRelativeDateTimeString(context, due, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS,0)
which is outputting strings formatted like
in 23 hours, 6:18am
I don't understand well the android documentation on this method.
Is there a built in way to strip off the time or change the comma to be more sentence like?
Either of "in 23 hours" or "in 23 hours at 6:18am" would be preferable to the current output.
Thanks.
Upvotes: 12
Views: 8213
Reputation: 2465
According to Android Documentation, you'll need to add a flag to display "42 mins ago", instead of "42 mins ago 01/01/2020".
DateUtils.getRelativeTimeSpanString(
item.createdAt.time,
Date().time,
DateUtils.MINUTE_IN_MILLIS,
FORMAT_ABBREV_RELATIVE
)
Can use FORMAT_ABBREV_RELATIVE flag to use abbreviated relative times, like "42 mins ago".
Upvotes: 1
Reputation: 2059
I have used a different method and gotten the "in 23 hours" result I wanted
DateUtils.getRelativeTimeSpanString(due,now, DateUtils.SECOND_IN_MILLIS)
Upvotes: 15