gpt4 book ai didi

java - 为什么 getRelativeTimeSpanString 需要 Context?

转载 作者:行者123 更新时间:2023-11-30 09:40:06 25 4
gpt4 key购买 nike

我想知道为什么 getRelativeTimeSpanString需要上下文吗? (抛开双关语)

public static CharSequence getRelativeTimeSpanString (Context c, long millis, boolean withPreposition)

最佳答案

查看源码:

public static CharSequence getRelativeTimeSpanString(Context c, long millis,
boolean withPreposition) {

long now = System.currentTimeMillis();
long span = now - millis;

if (sNowTime == null) {
sNowTime = new Time();
sThenTime = new Time();
}

sNowTime.set(now);
sThenTime.set(millis);

String result;
int prepositionId;
if (span < DAY_IN_MILLIS && sNowTime.weekDay == sThenTime.weekDay) {
// Same day
int flags = FORMAT_SHOW_TIME;
result = formatDateRange(c, millis, millis, flags);
prepositionId = R.string.preposition_for_time;
} else if (sNowTime.year != sThenTime.year) {
// Different years
int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE;
result = formatDateRange(c, millis, millis, flags);

// This is a date (like "10/31/2008" so use the date preposition)
prepositionId = R.string.preposition_for_date;
} else {
// Default
int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH;
result = formatDateRange(c, millis, millis, flags);
prepositionId = R.string.preposition_for_date;
}
if (withPreposition) {
Resources res = c.getResources();
result = res.getString(prepositionId, result);
}
return result;
}

关于java - 为什么 getRelativeTimeSpanString 需要 Context?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9570868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com