Java/android calculates tomorrow, today, yesterday, and the day after

Source: Internet
Author: User

java/android Calculate today, tomorrow, the day after, yesterday, the day before last method, the key is to know the time zone, if it is Beijing, the time zone East 8 area,

The system initial time is 1970-01-01 80:00:00, note is starting from eight o'clock, calculate the time to add back

Get the time zone method as follows:

Calendar.getinstance (). getTimeZone (). Getrawoffset ();

The calculation method is as follows:

-2: The day before yesterday,-1: Yesterday, 0: Today, 1: Tomorrow, 2: the day after

public static String Gettodayoryesterday (long date) {//date is a stored timestamp
        //time zone 8, the system initial time is 1970-01-01 80:00:00, note is starting from eight o'clock, Add it back to the calculation.
        int offSet = Calendar.getinstance (). getTimeZone (). Getrawoffset ();
        Long today = (System.currenttimemillis () +offset)/86400000;
        Long start = (date+offset)/86400000;
        Long intervaltime = Start-today;
        -2: The day before yesterday,-1: Yesterday, 0: Today, 1: Tomorrow, 2: The acquired
        String strdes= "";
        if (intervaltime==0) {
            strdes= getcontext (). Getresources (). getString (R.string.today);//Today
        }else if ( Intervaltime==-1) {
            strdes= getcontext (). Getresources (). getString (R.string.yesterday);//Yesterday
        }else{
            strdes=getformatdate (date);//Show Time directly
        }
        return strdes;
    }

Address: http://blog.csdn.net/jason_996/article/details/51314214

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.