Java Utililty Methods Date Subtract

List of utility methods to do Date Subtract

Description

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

Method

DatesubstractDaysFromDate(final Date date, final int substractDays)
Substract days to the given Date object and returns it.
final Calendar dateOnCalendar = Calendar.getInstance();
dateOnCalendar.setTime(date);
dateOnCalendar.add(Calendar.DATE, substractDays * -1);
return dateOnCalendar.getTime();
Datesubtract(Date date, int num)
subtract
Calendar canlendar = Calendar.getInstance();
canlendar.setTime(date);
canlendar.add(Calendar.DATE, -num);
return canlendar.getTime();
java.util.DatesubtractCertainYears(java.util.Date date, Integer years)
subtract Certain Years
java.util.Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.YEAR, -years);
return cal.getTime();
DatesubtractDate(Date date, int type, Integer quantity)
subtract Date
return manipulateDate(date, type, quantity, SUBTRACT);
DatesubtractDate(Date date, int type, Integer quantity)
subtract Date
return manipulateDate(date, type, quantity, SUBTRACT);
DatesubtractDay(final Date date)
Subtract one day from the supplied date
return addDays(date, -1);
DatesubtractDays(Date dt, int days)
Subtract a number of days
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
cal.add(Calendar.DATE, -days);
return cal.getTime();
DatesubtractDurationToDate(Date date, String duration)
Subtracts duration to date
final int negative = -1;
Date computedDate = null;
computedDate = computeDateFromDurationDate(date, duration, negative);
computedDate = computeDateFromDurationTime(computedDate, duration, negative);
return computedDate;
longsubtractNowDay(Date date)
subtract Now Day
final int aDaymi = 24 * 60 * 60 * 1000;
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
long dateTimeInMillis = calendar.getTimeInMillis();
Calendar nowCalendar = Calendar.getInstance();
nowCalendar.setTime(new Date());
long nowTimeInMillis = nowCalendar.getTimeInMillis();
return (nowTimeInMillis - dateTimeInMillis) / (aDaymi);
...
DatesubtractOrAddDayDuration(Date date, int duration)
subtract Or Add Day Duration
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, duration);
Date dateExpect = cal.getTime();
return dateExpect;