Edm*_*jas 14 java datetime android
getRelativeTimeSpanString()在android中使用内置方法DateUtil我无法得到"几分钟前""几天前"等时间文件说我应该收到的时间已过,而我得到的结果只是以这样的方式显示实际日期"可能12 2010",不知道这是否是一个错误或什么,但我用尽既getRelativeTimeSpanString (long time, long now, long minResolution)和getRelativeTimeSpanString (long startTime),双方只返回变量的实际日期"很长一段时间"
这是我的代码
private void setJoineddate() {
Date currentDate = new Date();
long currentDateLong = currentDate.getTime();
long oldDate = join_date.getTime();
CharSequence relativeTime = DateUtils
.getRelativeTimeSpanString(oldDate, currentDateLong, 0);
joindate.setText(relativeTime);
}
Run Code Online (Sandbox Code Playgroud)
vik*_*kki 10
不是错误.getRelativeTimeSpanString只会给你一个相对时间字符串,最长可达一周的时间.因此,如果您使用DateUtils.getRelativeTimeSpanString(time2, now, 0L, DateUtils.FORMAT_ABBREV_RELATIVE)以下值
long now = System.currentTimeMillis();
long time2 = now - DateUtils.WEEK_IN_MILLIS;
Run Code Online (Sandbox Code Playgroud)
1 October如果今天你会得到8 October,但是
long now = System.currentTimeMillis();
long time2 = now - DateUtils.WEEK_IN_MILLIS + 1;
Run Code Online (Sandbox Code Playgroud)
会给你的7 days ago.
试试这个代码
DateUtils.getRelativeTimeSpanString(oldDate, currentDateLong,
0L, DateUtils.FORMAT_ABBREV_ALL);
Run Code Online (Sandbox Code Playgroud)
它将返回Just now,3 minutes ago等等。阅读文档并使用第三个参数来修改函数返回的字符串。
| 归档时间: |
|
| 查看次数: |
8186 次 |
| 最近记录: |