Android Utililty Methods Date Interval Get

List of utility methods to do Date Interval Get

Description

The list of methods to do Date Interval Get are organized into topic(s).

Method

booleancheckIsIntervalDay(String startTime, String endTime)
check Is Interval Day
boolean isIntervalDay = false;
if ("00:00".compareTo(endTime) < 0
        && "12:00".compareTo(endTime) >= 0
        && "12:00".compareTo(startTime) < 0
        && "23:59".compareTo(startTime) >= 0) {
    isIntervalDay = true;
return isIntervalDay;
...
inttotalDays(Object o)
total Days
DateTime dateTime = narrowDateTime(o);
if (dateTime == null) {
    return 0;
long millis = dateTime.getMillis();
return (int) ((millis - millis % MILLIS_OF_DAY) / MILLIS_OF_DAY);
longcalculatorDaysAgo(String date, Locale locale, String format)
calculator Days Ago
Calendar today = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(format, locale);
try {
    cal.setTime(formatter.parse(date));
} catch (ParseException e) {
    DebugLog.e("ParseException");
    return 0;
...
longgetFirstInterval(Context context, long lastupdate, long updateinterval)
Gets the first interval for setting an alarm.
long now = System.currentTimeMillis();
long firstinterval = lastupdate - now + updateinterval;
if (firstinterval < 0) {
    Log.d(TAG, "Limit first interval from " + firstinterval
            + " to " + 0);
    firstinterval = 0;
} else if (firstinterval > updateinterval) {
    Log.d(TAG, "Limit first interval from " + firstinterval
...
StringtimeDifference(Date date)
Returns the string representation of time difference based on today date.
if (StringUtils.isNull(date)) {
    throw new NullPointerException("date cannot be null");
String returnTimediff;
Date nowdate = new Date();
int diffInDays = (int) ((nowdate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
int diffInHours = (int) ((nowdate.getTime() - date.getTime()) / (1000 * 60 * 60)) % 24;
int diffInMins = (int) ((nowdate.getTime() - date.getTime()) / (1000 * 60)) % 60;
...
StringgetTimeRangeStr(Date startDate, Date endDate)
Returns "22:00 - 23:00" for params "2014-02-09 22:00" and "2017-12-31 23:00"
return getTimeStr(startDate) + " - " + getTimeStr(endDate);
StringformatDuration(int duration)
Formats a duration in ms to something more readable.
int hours = (int) (duration / ONE_HOUR);
duration -= hours * ONE_HOUR;
int minutes = (int) (duration / ONE_MINUTE);
duration -= minutes * ONE_MINUTE;
int seconds = (int) (duration / ONE_SECOND);
String formattedDuration = "";
if (hours > 0) {
    formattedDuration = String.format("%d:%02d:%02d", hours,
...
StringcalcTimeBetween(Date start, Date end)
calc Time Between
int SECOND = 1000;
int MINUTE = SECOND * 60;
int HOUR = MINUTE * 60;
int DAY = HOUR * 24;
int milliSeconds = Math.round(end.getTime() - start.getTime());
if (milliSeconds > DAY) {
    return String.format("%d days", Math.round(milliSeconds / DAY));
if (milliSeconds < DAY && milliSeconds > HOUR) {
    return String.format("%d hours",
            Math.round(milliSeconds / HOUR));
if (milliSeconds < HOUR) {
    return String.format("%d minutes",
            Math.round(milliSeconds / MINUTE));
return null;
intgetOffectDay(long date1, long date2)
get Offect Day
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int y1 = calendar1.get(Calendar.YEAR);
int y2 = calendar2.get(Calendar.YEAR);
int d1 = calendar1.get(Calendar.DAY_OF_YEAR);
int d2 = calendar2.get(Calendar.DAY_OF_YEAR);
...
intgetOffectDay(long date1, long date2)
get Offect Day
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis(date1);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(date2);
int y1 = calendar1.get(Calendar.YEAR);
int y2 = calendar2.get(Calendar.YEAR);
int d1 = calendar1.get(Calendar.DAY_OF_YEAR);
int d2 = calendar2.get(Calendar.DAY_OF_YEAR);
...