Acquisition of time in instant chat software in Android development

Source: Internet
Author: User

`/** * 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.