Here you can find the source of isYesterday(long date)
Parameter | Description |
---|---|
date | - Date to check. |
public static boolean isYesterday(long date)
/******************************************************************************* * Copyright (c) 2012 rmateus.//w w w . j a v a2 s . c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v2.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html ******************************************************************************/ import android.content.Context; import android.text.format.DateUtils; import cm.aptoide.pt.R; import java.text.DateFormatSymbols; import java.util.Calendar; 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 mCtx; private static DateTimeUtils instance; /** * 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 contructor, needed to get access to the application context & strings for i18n * @param context Context * @return DateTimeUtils singleton instanec * @throws Exception */ public static DateTimeUtils getInstance(Context context) { mCtx = context; if (instance == null) { instance = 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 instance; } }