Android Long to Date Convert isYesterday(long date)

Here you can find the source of isYesterday(long date)

Description

Checks if the given date is yesterday.

Parameter

Parameter Description
date - Date to check.

Return

TRUE if the date is yesterday, FALSE otherwise.

Declaration

public static boolean isYesterday(long date) 

Method Source Code

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;
    }
}

Related

  1. hrColMin(final long time, final boolean alwaysIncludeHours)
  2. hrColMinColSec(final long time, final boolean alwaysIncludeHours)
  3. isAtMostNMonthsAgo(long date, int howMany)
  4. isAtMostNWeeksAgo(long date, int howMany)
  5. isYesterday(long date)
  6. longTimeToDate(long miliseconds)
  7. longTimeToString(int i)
  8. longToCalendar(Long time)
  9. longToSqlDateFormat(long date)