-5

Problem

Given a Date.Add specified number of days to endDate.

Below is the doubleDate function that I need to define.

public static Date doubleDate(Date endDate,int noOFDays){
}

Solution:

public static Date doubleDate(Date endDate,int noOFDays){
    Calendar c = Calendar.getInstance();    
    c.setTime(endDate);
    c.add(Calendar.DATE,noOFDays);
    return c.getTime();     
}

Can anyone guide me which method should I use to double the given endDate?

Community
  • 1
  • 1

1 Answers1

0

This is how to add days to a given date.

public static Date addDate(Date endDate, int noOFDays) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(endDate);
    cal.add(Calendar.DATE, noOFDays);

    return cal.getTime();
}
Avitus
  • 15,640
  • 6
  • 43
  • 53