如果您正在使用Eclipse IDE
,请尝试GrepCode_Plugin
从本教程安装GrepCode_Plugin
完成后,GrepCode Search
使用android.text.format.DateUtils
. 它会列出你所有的文件。尝试下载最新的。
从该文件中获取方法并根据您的需要进行修改。
供您参考,我将把列出的方法放在android 4.1.1_r1
public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution,
int flags) {
Resources r = Resources.getSystem();
boolean abbrevRelative = (flags & (FORMAT_ABBREV_RELATIVE | FORMAT_ABBREV_ALL)) != 0;
boolean past = (now >= time);
long duration = Math.abs(now - time);
int resId;
long count;
if (duration < MINUTE_IN_MILLIS && minResolution < MINUTE_IN_MILLIS) {
count = duration / SECOND_IN_MILLIS;
if (past) {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_num_seconds_ago;
} else {
resId = com.android.internal.R.plurals.num_seconds_ago;
}
} else {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_in_num_seconds;
} else {
resId = com.android.internal.R.plurals.in_num_seconds;
}
}
} else if (duration < HOUR_IN_MILLIS && minResolution < HOUR_IN_MILLIS) {
count = duration / MINUTE_IN_MILLIS;
if (past) {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_num_minutes_ago;
} else {
resId = com.android.internal.R.plurals.num_minutes_ago;
}
} else {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_in_num_minutes;
} else {
resId = com.android.internal.R.plurals.in_num_minutes;
}
}
} else if (duration < DAY_IN_MILLIS && minResolution < DAY_IN_MILLIS) {
count = duration / HOUR_IN_MILLIS;
if (past) {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_num_hours_ago;
} else {
resId = com.android.internal.R.plurals.num_hours_ago;
}
} else {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_in_num_hours;
} else {
resId = com.android.internal.R.plurals.in_num_hours;
}
}
} else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) {
count = getNumberOfDaysPassed(time, now);
if (past) {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_num_days_ago;
} else {
resId = com.android.internal.R.plurals.num_days_ago;
}
} else {
if (abbrevRelative) {
resId = com.android.internal.R.plurals.abbrev_in_num_days;
} else {
resId = com.android.internal.R.plurals.in_num_days;
}
}
} else {
// We know that we won't be showing the time, so it is safe to pass
// in a null context.
return formatDateRange(null, time, time, flags);
}
String format = r.getQuantityString(resId, (int) count);
return String.format(format, count);
}