1

Android 操作系统使用什么来格式化通知中的日期和时间?

我假设它使用了 DateUtils.formatSameDayTime,但它并没有完全做到这一点。逻辑看起来相同,但格式并不完全相同。例如,当 formatSameDayTime 返回“8/6/13”时,通知将显示“2013-08-06”(基于我的系统设置)。

编辑:

这是我目前的解决方案。但它是最好的吗?

public static final CharSequence formatSameDayTimeCustom(Context context, long then) {
    if (DateUtils.isToday(then)) {
        return DateFormat.getTimeFormat(context).format(new Date(then));
    }
    else {
        final String format = Settings.System.getString(context.getContentResolver(), Settings.System.DATE_FORMAT);
        return new SimpleDateFormat(format).format(new Date(then));
    }
}
4

0 回答 0