Home>

android SMS time display is very fine,First, the SMS time saved in the SMS database mmssms.db is a long number.The query action ends,After getting this value,Will do the conversion,The specific conversion action is completed in the formattimestampstring function of messageutils.java;

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);
}

As can be seen from the second specifically implemented function,Android determines the display time format based on the current time as the basis of comparison:

1. If the year in the current SMS time is different from the current year on the phone,Displays the year, month, and day.Do not show specific pointsSuch as:2010-6-30;

2. If the time of the text message is in the same year as the current time of the mobile phone,But not the same day,Only the day of the month,For example:June 29;

3. If it is a text message of the day,Will calculate whether it is a morning or afternoon text message,At the same time, the recorded message is displayed.Example:12:55 pm;

Considering it all,This display design is still very reasonable

  • Previous PHP related operations on the folder (traverse, calculate the size)
  • Next Introduction to basic shortcuts and configuration for Python IDE PyCharm