Android 短信列表的时间显示

2014-11-24 10:44:13 ? 作者: ? 浏览: 0

时间转换:


public static String formatTimeStampString(Context context, long when) {
return formatTimeStampString(context, when, false);
}


formatTimeStampString


public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
Time then = new Time();
then.set(when);
Time now = new Time();
now.setToNow();

// Basic settings for formatDateTime() we want for all cases.
int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT |
DateUtils.FORMAT_ABBREV_ALL |
DateUtils.FORMAT_CAP_AMPM;

// If the message is from a different year, show the date and year.
if (then.year != now.year) {
format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
} else if (then.yearDay != now.yearDay) {
// If it is from a different day than today, show only the date.
format_flags |= DateUtils.FORMAT_SHOW_DATE;
} else {
// Otherwise, if the message is from today, show the time.
format_flags |= DateUtils.FORMAT_SHOW_TIME;
}

// If the caller has asked for full details, make sure to show the date
// and time no matter what we've determined above (but still make showing
// the year only happen if it is a different year from today).
if (fullFormat) {
format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
}

return DateUtils.formatDateTime(context, when, format_flags);
}


从第二个具体实现的函数可以看出来,Android是根据当前的时间为比较的依据来决定显示的时间格式:


综合考虑下来,这样的显示设计还是很合理的…


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: