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

StringdateAddHours(Date time, int hours, SimpleDateFormat dateFormat)
date Add Hours
long timeLong = time.getTime() / 1000 + 60l * 60 * hours;
time.setTime(timeLong * 1000);
String timeStr = dateFormat.format(time);
return timeStr;
DatedateAddMinutes(Date date, int minutes)
date Add Minutes
if (date == null)
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MINUTE, minutes);
return cal.getTime();
StringdateAddMM(Date date, int i)
date Add MM
Date currTime = addMM(date, i);
SimpleDateFormat format = new SimpleDateFormat(DATETIME_FORMAT_YYYYMMDDHHMMSS);
return format.format(currTime);
DatedateAddMonths(Date date, int addMonths)
date Add Months
if (date == null)
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, addMonths);
return cal.getTime();
DatedateAddSpaceMilliSecond(Date date, int milliSecond)
date Add Space Milli Second
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MILLISECOND, milliSecond);
return cal.getTime();