Java 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

DateaddDays(Date when, int amount)
add Days
return add(when, Calendar.DAY_OF_YEAR, amount);
CalendaraddDays(int count, Calendar timestamp)
Adds or subtracts the corresponding time field, does not perform any alignment.
timestamp.add(Calendar.DATE, count);
return timestamp;
DateaddDaysToCurrentDate(Integer dayIncrement)
add Days To Current Date
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.add(Calendar.DATE, dayIncrement);
return calendar.getTime();
DateaddInteger(Date date, int dateType, int amount)
add Integer
if (date != null) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(dateType, amount);
    date = calendar.getTime();
return date;
DateaddSeconds(Date date1, long secs)
add Seconds
return new Date(date1.getTime() + (secs * 1000));
StringdateAdd(Date date, int days)
date Add
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String toDate = dateFormat.format(new Date());
return dateAdd(toDate, days);
DatedateAdd(Date date, int days)
Convenience method to add specified number of days to the given date
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, days);
return cal.getTime();
DatedateAdd(Date date, int field, int amount)
date Add
Calendar calendar = Calendar.getInstance();
try {
    calendar.setTime(date);
    calendar.add(field, amount);
    return calendar.getTime();
} catch (Exception e) {
    System.out.println("DateAdd Exception :" + e);
    return null;
...
DatedateAdd(Date date, int type, int num)
date Add
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(type, num);
return c.getTime();
DatedateAdd(Date date, int val)
date Add
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, val);
date = calendar.getTime();
return date;