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

StringaddDate(String date1, String addpart, int num)
add Date
return addTime(date1, addpart, num).substring(0, 10);
java.util.DateaddDate(String dt, long day)
add Date
if (dt == null) {
    throw new IllegalArgumentException("dt can not be null");
int len = dt.length();
if (!(len == 8 || len == 14)) {
    throw new IllegalArgumentException("dt length must be 8 or 14 (yyyyMMdd or yyyyMMddHHmmss)");
if (len == 8) {
...
DateaddDateByDays(int days)
add Date By Days
return addDateByDays(getCurrentDate(), days);
DateaddDateDay(int day)
add Date Day
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, day);
return calendar.getTime();
voidaddDateParam(String dtstr, boolean start, List where)
Adds a date parameter (start, end) as filter to the SQL where clause
if (dtstr != null && isValidDate(dtstr)) {
    where.add("c.loginTime " + (start ? ">= '" : "<= '") + dtstr.substring(0, 4) + "-"
            + dtstr.substring(4, 6) + "-" + dtstr.substring(6) + " 00:00:00.000'");
DateaddDates(Date startDate, int days)
add Dates
Calendar cc = Calendar.getInstance();
if (startDate != null) {
    cc.setTime(startDate);
    cc.add(Calendar.DATE, days);
    return cc.getTime();
} else {
    return null;
DateaddDay(Date date, int days)
add Day
Calendar cale = Calendar.getInstance();
cale.setTime(date);
cale.add(Calendar.DAY_OF_YEAR, days);
return cale.getTime();
DateaddDays(Date date1, long days)
add Days
return addSeconds(date1, days * ONE_DAY_SECONDS);
DateaddDays(Date dateToAdd, int numberOfDay)
Add given number of days to a date.
if (dateToAdd == null) {
    throw new IllegalArgumentException("Date can't be null!");
Calendar tempCal = Calendar.getInstance();
tempCal.setTime(dateToAdd);
tempCal.add(Calendar.DATE, numberOfDay);
return tempCal.getTime();
DateaddDays(Date target, int days)
add Days
long msPerDay = 1000 * 60 * 60 * 24;
long msTarget = target.getTime();
long msSum = msTarget + (msPerDay * days);
Date result = new Date();
result.setTime(msSum);
return result;