Android:getRelativeTime示例 [英] Android: getRelativeTime example
本文介绍了Android:getRelativeTime示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
我想你正在谈论 c $ c> getRelativeDateTimeString ,这是您链接指向的。
示例对于现在
,其中包含所有参数的评论:
Date now = new日期();
String str = DateUtils.getRelativeDateTimeString(
这个,//假设你在一个活动或其他Context子类
now.getTime(),//时间显示
DateUtils.MINUTE_IN_MILLIS,//分辨率,这将只显示
//分钟(不3秒前)
DateUtils.WEEK_IN_MILLIS,//时间将
//切换到默认日期而不是跨度的最大分辨率,这不会
//显示3周前,而是完全日期而不是
0); //最终标志
MINUTE_IN_MILLIS
的其他值和 YEAR_IN_MILLIS
包括:
-
SECOND_IN_MILLIS
-
MINUTE_IN_MILLIS
-
HOUR_IN_MILLIS
-
DAY_IN_MILLIS
-
WEEK_IN_MILLIS
-
YEAR_IN_MILLIS
- 任何以毫秒为单位的自定义值
Can someone show me an example how to properly use the getRelativetime() that is detailed here
解决方案
I guess you are talking about getRelativeDateTimeString
, which is pointed to by your link.
Example for now
, with comments detailing all params:
Date now = new Date();
String str = DateUtils.getRelativeDateTimeString(
this, // Suppose you are in an activity or other Context subclass
now.getTime(), // The time to display
DateUtils.MINUTE_IN_MILLIS, // The resolution. This will display only
// minutes (no "3 seconds ago")
DateUtils.WEEK_IN_MILLIS, // The maximum resolution at which the time will switch
// to default date instead of spans. This will not
// display "3 weeks ago" but a full date instead
0); // Eventual flags
Other values for MINUTE_IN_MILLIS
and YEAR_IN_MILLIS
include:
SECOND_IN_MILLIS
MINUTE_IN_MILLIS
HOUR_IN_MILLIS
DAY_IN_MILLIS
WEEK_IN_MILLIS
YEAR_IN_MILLIS
- Any custom value in milliseconds
这篇关于Android:getRelativeTime示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文