Android: getRelativeTime example

后端 未结 2 1462
青春惊慌失措
青春惊慌失措 2020-12-29 07:33

Can someone show me an example how to properly use the getRelativeDateTimeString() that is detailed here.

2条回答
  •  忘掉有多难
    2020-12-29 07:53

    I think a better question would specify what you want as an output. However, here's an example:

     DateUtils.getRelativeTimeSpanString(yourContext, theEventInMillis, 
                                         DateUtils.MINUTE_IN_MILLIS, 
                                         DateUtils.FORMAT_NO_NOON);
    

    This will format theEventInMillis relative to whatever the system's current time is. It will show changes in minutes (0 minutes ago, 2 minutes ago, 3 hours ago, 1 day ago, etc) until the difference reaches a week, then it will just post the full date. The flags field (0 in this case, last argument) you can use to control how the resulting string is rendered, but you should check the docs to see what fits your needs.

提交回复
热议问题