List of utility methods to do Date Add
Timestamp | addWeeks(Date date, int amount) add Weeks return add(date, Calendar.WEEK_OF_YEAR, amount);
|
Date | addWeeks(Date date, int amount) Adds a number of weeks to a date returning a new object. return add(date, Calendar.WEEK_OF_YEAR, amount);
|
Date | addYearToDate(Date date, int yearsToBeAdded) Add / Subtract given no of years to Date . if (StringUtils.isNull(date)) { throw new NullPointerException("date cannot be null"); return add(date, Calendar.YEAR, yearsToBeAdded); |
Timestamp | addYears(Date date, int amount) add Years return add(date, Calendar.YEAR, amount);
|
Date | addYears(Date date, int amount) Adds a number of years to a date returning a new object. return add(date, Calendar.YEAR, amount);
|
Date | dateByAddHoursAndMinutes(Date date, int hours, int minutes) date By Add Hours And Minutes Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, minutes); Date dateFinal = new Date(); dateFinal.setTime(calendar.getTimeInMillis()); return dateFinal; |
Date | getDateAdd(Date date, int amount) get Date Add Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(GregorianCalendar.DATE, amount); return cal.getTime(); |
Date | addDaysToDate(Date date, int days) add Days To Date long epochTime = date.getTime() + (days * ONE_DAY_IN_MILLIS); return new Date(epochTime); |
Date | addTimeInterval(Date origin, int value, int unit) add Time Interval Calendar cal = Calendar.getInstance();
cal.setTime(origin);
cal.add(unit, value);
return cal.getTime();
|