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

Dateadd(Date date, int calendarField, int amount)
Used internally to add/subtract amount to specific calendar field.
if (StringUtils.isNull(date)) {
    throw new NullPointerException("date cannot be null");
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(calendarField, amount);
return c.getTime();
Timestampadd(Date date, int calendarField, int amount)
add
if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(calendarField, amount);
return new Timestamp(c.getTimeInMillis());
Dateadd(Date date, int calendarField, int amount)
Adds to a date returning a new object.
if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(calendarField, amount);
return c.getTime();
DateaddDay(Date date, int days)
add Day
Calendar c = getCalendar(date);
if (c == null)
    return null;
c.add(Calendar.DAY_OF_MONTH, days);
return c.getTime();
TimestampaddDays(Date date, int amount)
add Days
return add(date, Calendar.DAY_OF_MONTH, amount);
DateaddDays(Date date, int amount)
Adds a number of days to a date returning a new object.
return add(date, Calendar.DAY_OF_MONTH, amount);
DateaddDaysToDate(Date date, int daysToBeAdded)
Add / Subtract given no of days to Date .
if (StringUtils.isNull(date)) {
    throw new NullPointerException("date cannot be null");
return add(date, Calendar.DATE, daysToBeAdded);
TimestampaddHours(Date date, int amount)
add Hours
return add(date, Calendar.HOUR_OF_DAY, amount);
DateaddHours(Date date, int amount)
Adds a number of hours to a date returning a new object.
return add(date, Calendar.HOUR_OF_DAY, amount);
DateaddHoursToDate(Date date, int hoursToBeAdded)
Add / Subtract given no of hours to Date .
if (StringUtils.isNull(date)) {
    throw new NullPointerException("date cannot be null");
return add(date, Calendar.HOUR, hoursToBeAdded);