Essential Android Time Utils edit forum

To check within a period

This example will help to verify the given time is within a period or not.

To check the time is today, We can use DateUtils class

boolean isToday = DateUtils.isToday(timeInMillis);

To check the time is within a week,

private static boolean isWithinWeek(final long millis) {
    return System.currentTimeMillis() - millis <= (DateUtils.WEEK_IN_MILLIS - DateUtils.DAY_IN_MILLIS);
}

To check the time is within a year,

private static boolean isWithinYear(final long millis) {
    return System.currentTimeMillis() - millis <= DateUtils.YEAR_IN_MILLIS;
}

To check the time is within a number day of day including today,

public static boolean isWithinDay(long timeInMillis, int day) {
    long diff = System.currentTimeMillis() - timeInMillis;

    float dayCount = (float) (diff / DateUtils.DAY_IN_MILLIS);

    return dayCount < day;
}

Note : DateUtils is android.text.format.DateUtils


Table Of Contents
39 ACRA
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
180 Time Utils
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close