Android的短信的时间的显示做的很精细,首先保存在短信数据库mmssms.db中的短信时间都是Long型的数字,查询动作结束,取到这个值之后,会做转换,具体转换的动作在MessageUtils.java的formatTimeStampString函数中完成;
long when) { return formatTimeStampString(context, when, false); }
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

 

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

相关文章:

  • 2022-12-23
  • 2021-12-02
  • 2022-02-21
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-11-05
  • 2021-05-24
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案