Android Utililty Methods Date Add

List of utility methods to do Date Add

Description

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

Method

TimestampaddWeeks(Date date, int amount)
add Weeks
return add(date, Calendar.WEEK_OF_YEAR, amount);
DateaddWeeks(Date date, int amount)
Adds a number of weeks to a date returning a new object.
return add(date, Calendar.WEEK_OF_YEAR, amount);
DateaddYearToDate(Date date, int yearsToBeAdded)
Add / Subtract given no of years to Date .
if (StringUtils.isNull(date)) {
    throw new NullPointerException("date cannot be null");
return add(date, Calendar.YEAR, yearsToBeAdded);
TimestampaddYears(Date date, int amount)
add Years
return add(date, Calendar.YEAR, amount);
DateaddYears(Date date, int amount)
Adds a number of years to a date returning a new object.
return add(date, Calendar.YEAR, amount);
DatedateByAddHoursAndMinutes(Date date, int hours, int minutes)
date By Add Hours And Minutes
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
Date dateFinal = new Date();
dateFinal.setTime(calendar.getTimeInMillis());
return dateFinal;
DategetDateAdd(Date date, int amount)
get Date Add
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(GregorianCalendar.DATE, amount);
return cal.getTime();
DateaddDaysToDate(Date date, int days)
add Days To Date
long epochTime = date.getTime() + (days * ONE_DAY_IN_MILLIS);
return new Date(epochTime);
DateaddTimeInterval(Date origin, int value, int unit)
add Time Interval
Calendar cal = Calendar.getInstance();
cal.setTime(origin);
cal.add(unit, value);
return cal.getTime();