Java Utililty Methods Date Adjust

List of utility methods to do Date Adjust

Description

The list of methods to do Date Adjust are organized into topic(s).

Method

java.util.DateadjustDate(Date dtDate, int iYears, int iMonths, int iDays, int iHours, int iMinutes, int iSeconds)
Adjusts the Date passed in by the appropriate amounts.
if (dtDate == null)
    return null;
Calendar cal = Calendar.getInstance();
Calendar calNew = Calendar.getInstance();
cal.setTime(dtDate);
calNew.setTime(dtDate);
calNew.set(cal.get(Calendar.YEAR) + iYears, cal.get(Calendar.MONTH) + iMonths,
        cal.get(Calendar.DAY_OF_MONTH) + iDays, cal.get(Calendar.HOUR_OF_DAY) + iHours,
...
DateadjustDays(Date startingDate, int deltaDays)
Takes a Date and moves in the desired amount of days.
Calendar cal = Calendar.getInstance();
cal.setTime(startingDate);
cal.add(Calendar.DATE, deltaDays);
return cal.getTime();
DateadjustHour(Date dt, int hour)
adjust Hour
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
cal.add(Calendar.HOUR, hour);
return cal.getTime();
DateadjustHourAndMinute(Date n)
adjust Hour And Minute
if (n == null)
    n = new Date();
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
cal.setTime(n);
cal.set(Calendar.MINUTE, minutes);
cal.set(Calendar.HOUR_OF_DAY, hour);
...
DateadjustTime(Date date, int hour, int minute, int second)
adjust Time
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.HOUR, hour);
c.add(Calendar.MINUTE, minute);
c.add(Calendar.SECOND, second);
return c.getTime();
voidadjustToDayStartAndEnd(Date from, Date to)
Set a period to day start and end.
adjustToDayStart(from);
adjustToDayEnd(to);
DategetAdjustDayResetTime(Date date, int adjustAmount)
get Adjust Day Reset Time
if (date == null) {
    return null;
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
...
DategetAdjustedDate(Date original, int millisecondAdjustment)
get Adjusted Date
Date result = null;
if (original != null) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(original);
    cal.add(Calendar.MILLISECOND, millisecondAdjustment);
    result = cal.getTime();
return result;
...
DategetTimeWithAdjustment(Date date, boolean carryover)
get Time With Adjustment
Calendar cal = Calendar.getInstance();
if (date != null) {
    cal.setTime(date);
if (carryover) {
    cal.add(Calendar.DAY_OF_YEAR, 1);
return cal.getTime();
...