Java Utililty Methods Time Add

List of utility methods to do Time Add

Description

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

Method

DateaddTime(Date aDate, int timeToAdd, int timeUnits)
Add time to a date with generic settings.
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(aDate);
cal.add(timeUnits, timeToAdd);
return cal.getTime();
DateaddTime(Date aDate, int timeToAdd, int timeUnits)
add Time
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(aDate);
cal.add(timeUnits, timeToAdd);
return cal.getTime();
DateaddTime(Date baseDate, int amount, int datePart)
Adds the specified part of date or time to the provided date instance.
Calendar cal = Calendar.getInstance();
synchronized (cal) {
    cal.setTime(baseDate);
    cal.add(datePart, amount);
return cal.getTime();
DateaddTime(Date current, Date toadd)
add Time
Calendar cal1 = Calendar.getInstance();
cal1.setTime(current);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(toadd);
cal1.add(Calendar.HOUR_OF_DAY, cal2.get(Calendar.HOUR_OF_DAY));
cal1.add(Calendar.MINUTE, cal2.get(Calendar.MINUTE));
cal1.add(Calendar.SECOND, cal2.get(Calendar.SECOND));
return cal1.getTime();
...
DateaddTime(Date date, Date addTime)
add Time
Calendar calendar = Calendar.getInstance();
calendar.setTime(addTime);
int addHour = calendar.get(Calendar.HOUR);
int addMinute = calendar.get(Calendar.MINUTE);
int addSecond = calendar.get(Calendar.SECOND);
int addMillisecond = calendar.get(Calendar.MILLISECOND);
calendar.setTime(date);
calendar.add(Calendar.MILLISECOND, addMillisecond);
...
DateaddTime(Date date, int field, int value)
add Time
Calendar cal = cal(date);
cal.add(field, value);
return cal.getTime();
DateaddTime(Date date, int field, int value)
add Time
return addTime(date, field, value, false);
DateaddTime(Date date, int mode, int amount)
add Time
Calendar cal = Calendar.getInstance();
if (date != null)
    cal.setTime(date);
cal.add(mode, amount);
return cal.getTime();
DateaddTime(Date date, String time)
Deprecated!
int hour = Integer.parseInt(time.substring(0, 2));
int minute = Integer.parseInt(time.substring(2, 4));
int second = Integer.parseInt(time.substring(4, 6));
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.HOUR, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
...
DateaddTime(Date source, int hours, int minutes, int second)
add Time
if (source == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(source);
cal.add(Calendar.HOUR_OF_DAY, hours);
cal.add(Calendar.MINUTE, minutes);
cal.add(Calendar.SECOND, second);
...