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