`/** * Convert to a string type of descriptive time based on a long type of timestamp * Call history if it happens today: "15:30" * occurred yesterday: "Yesterday 8:23" * occurred the day before yesterday: "4:56 the day before" * More Morning: "2016/04/15" * @param timestample * @return * * //timestample is the time the chat record occurred Public StaticStringGetTime(LongTimestample) {//Get the time stamp now LongNow=system.currenttimemillis ();//In Java, the number of int type is division, only the integer, it is to take advantage of this, //In the following days, as long as not 24 points yesterday, whether the difference between 1s or 23 hours, the result of division is the day before, intDay= (int) (now/ +/ -/ -/ --timestample/ +/ -/ -/ -);Switch(day) {//If it is 0 this means today, show time Case 0: SimpleDateFormat sdf=NewSimpleDateFormat ("hh:mm");returnSdf.format (timestample);//If the 1 description is yesterday, show yesterday + Time Case 1: SimpleDateFormat sdf1=NewSimpleDateFormat ("hh:mm");return "Yesterday"+sdf1.format (timestample);//If the 1 description is the day before yesterday, show the day before + time Case 2: SimpleDateFormat sdf2=NewSimpleDateFormat ("hh:mm");return "The day before"+sdf2.format (timestample);//Results greater than 2 only show month date default: SimpleDateFormat sdf3=NewSimpleDateFormat ("Yyyy:MM:dd");returnSdf3.format (timestample);
Acquisition of time in instant chat software in Android development