Android 短信列表的时间显示
来源:互联网 发布:卸载office2016软件 编辑:程序博客网 时间:2024/05/10 08:52
Android 中短信的时间的显示做的很精细。首先,保存在短信数据库 mmssms.db 中的短信时间都是 Long 型的数字。当查询动作结束时,取到这个值之后,会做转换,具体转换的动作在MessageUtils.java的formatTimeStampString函数中完成。
- public static String formatTimeStampString(Context context, long when) {
- return formatTimeStampString(context, when, false);
- }
- 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是根据当前的时间为比较的依据来决定显示的时间格式:
1. 如果当前的短信时间中年份跟手机当前的年份不一致,则显示年月日,不显示具体的几点几分,如:2010-6-30;
2. 如果短信的时间跟手机当前时间在同一年,但不是同一天,则只显示月日,如:6月29日;
3.如果是当天的短信,则会计算是上午还是下午的短信,同时显示几点几分记录的该短信,如:下午 12:55;
- Android 短信列表的时间显示
- android 聊天列表页面的时间显示问题--1(星期显示,暂无分块)
- Android的时间显示
- .net 时间函数的显示效果列表
- 仿iphone中短信/通话记录的时间显示
- 下拉列表显示时间
- android发送短信、会话列表、短信详情
- Android 获取短信会话列表
- Android 获取短信会话列表
- Android 获取短信会话列表
- Android短信列表源码分析
- android学习笔记31--------------短信会话列表信息的获取
- Android-通讯录:获取短信会话列表(包括群发的)
- android 动态的显示时间
- 自定义List列表显示短信内容,仿iphone短信气泡
- easyui列表中的/Date(1352649600000)/时间显示的问题
- android列表显示的SimpleAdapter适配器
- Android-ListView的图文列表显示
- UBUNTU安装PHP mysql
- SSH配置之web.xml .
- TCP/IP详解学习笔记(5)-IP选路,动态选路,和一些细节
- mvn 结构下spring+axis2开发webservice服务器端、客户端
- JNI中反向访问java对象
- Android 短信列表的时间显示
- Objective C 原型模式
- EXTJS分别用数组和JSON对象数组填充表格数据
- java DES加密解密文件
- 浅谈android的selector,背景选择器
- .net 上传图片 判断是否为真正的图片 防止木马
- LoadRunner 11 下载、安装、破解
- C# 中的委托和事件
- XML: 使用XmlDocument 与 XmlReader 类