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

intDaysBetween(Date beginDate, Date endDate)
Days Between
Calendar cal = Calendar.getInstance();
cal.setTime(beginDate);
long beginTime = cal.getTimeInMillis();
cal.setTime(endDate);
long EndTime = cal.getTimeInMillis();
long between_days = (EndTime - beginTime) / (1000 * 3600 * 24);
return Integer.parseInt(String.valueOf(between_days));
longcalculateDiffInDays(Date date1, Date date2)
Calculates the difference between the given Date in days.
if (StringUtils.isNull(date1)) {
    throw new NullPointerException("date1 cannot be null");
if (StringUtils.isNull(date2)) {
    throw new NullPointerException("date2 cannot be null");
long differenceInDays = (calculateDiffInHours(date1, date2)) / 24;
return differenceInDays;
...
longcalculateDiffInHours(Date date1, Date date2)
Calculates the difference between the given Date in hours.
if (StringUtils.isNull(date1)) {
    throw new NullPointerException("date1 cannot be null");
if (StringUtils.isNull(date2)) {
    throw new NullPointerException("date2 cannot be null");
long differenceInHours = (calculateDiffInMilliSeconds(date1, date2))
        / MILLIS_PER_HOUR;
...
longcalculateDiffInMilliSeconds(Date date1, Date date2)
Calculates the difference between the given Date in milliseconds.
if (StringUtils.isNull(date1)) {
    throw new NullPointerException("date1 cannot be null");
if (StringUtils.isNull(date2)) {
    throw new NullPointerException("date2 cannot be null");
long milliseconds1 = date1.getTime();
long milliseconds2 = date2.getTime();
...
longcalculateDiffInMinutes(Date date1, Date date2)
Calculates the difference between the given Date in minutes.
if (StringUtils.isNull(date1)) {
    throw new NullPointerException("date1 cannot be null");
if (StringUtils.isNull(date2)) {
    throw new NullPointerException("date2 cannot be null");
long differenceInMinutes = (calculateDiffInMilliSeconds(date1,
        date2)) / MILLIS_PER_MINUTE;
...
StringdateDiff(String startTime, String endTime)
date Diff
String result = "";
SimpleDateFormat sd = new SimpleDateFormat(YMD_DASH_WITH_TIME);
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ns = 1000;
long diff;
long day = 0;
...
LongdateDiff(String startTime, String endTime, String format, String str)
date Diff
SimpleDateFormat sd = new SimpleDateFormat(format);
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
long ns = 1000;
long diff;
long day = 0;
long hour = 0;
...
intdayDiff(Date date1, Date date2)
day Diff
long diff = date1.getTime() - date2.getTime();
return (int) (diff / DAY);
DatedayOffset(Date date, int offset)
day Offset
return offsetDate(date, Calendar.DATE, offset);
longdaysBetweenDate(Date date1, Date date2)
days Between Date
long d = date1.getTime() - date2.getTime();
return d / 86400000;