Here you can find the source of isYesterday(long date)
Parameter | Description |
---|---|
date | - Date to check. |
public static boolean isYesterday(long date)
import java.text.DateFormatSymbols; import java.util.Calendar; import android.content.Context; import android.text.format.DateUtils; import com.loganlinn.pivotaltrackie.R; public class Main{ private static String mTimestampLabelYesterday; private static String mTimestampLabelToday; private static String mTimestampLabelJustNow; private static String mTimestampLabelMinutesAgo; private static String mTimestampLabelHoursAgo; private static String mTimestampLabelHourAgo; private static Context sContext; private static DateTimeUtils sInstance; /**/*from www . j av a 2 s.c om*/ * Checks if the given date is yesterday. * * @param date - Date to check. * @return TRUE if the date is yesterday, FALSE otherwise. */ public static boolean isYesterday(long date) { final Calendar currentDate = Calendar.getInstance(); currentDate.setTimeInMillis(date); final Calendar yesterdayDate = Calendar.getInstance(); yesterdayDate.add(Calendar.DATE, -1); return yesterdayDate.get(Calendar.YEAR) == currentDate .get(Calendar.YEAR) && yesterdayDate.get(Calendar.DAY_OF_YEAR) == currentDate .get(Calendar.DAY_OF_YEAR); } /** * Singleton constructor, needed to get access to the application context & strings for i18n * @param context Context * @return DateTimeUtils singleton instance * @throws Exception */ public static DateTimeUtils getInstance(Context context) { sContext = context; if (sInstance == null) { sInstance = new DateTimeUtils(); mTimestampLabelYesterday = context.getResources().getString( R.string.WidgetProvider_timestamp_yesterday); mTimestampLabelToday = context.getResources().getString( R.string.WidgetProvider_timestamp_today); mTimestampLabelJustNow = context.getResources().getString( R.string.WidgetProvider_timestamp_just_now); mTimestampLabelMinutesAgo = context.getResources().getString( R.string.WidgetProvider_timestamp_minutes_ago); mTimestampLabelHoursAgo = context.getResources().getString( R.string.WidgetProvider_timestamp_hours_ago); mTimestampLabelHourAgo = context.getResources().getString( R.string.WidgetProvider_timestamp_hour_ago); } return sInstance; } }