Question

I am having through getting setting the value of a GregorianCalendar to that of another one + 4 years. I see there s the add method in the class but this accepts an int and I am trying to pass a GregorianCalendar type.

public GregorianCalendar getEnrollmentDate(GregorianCalendar enrollmentDate){
    return enrollmentDate;
}
public void setProjectedGraduationDate(GregorianCalendar projectedGraduationDate){
    Calendar cal = new GregorianCalendar();
    cal.setTime(this.enrollmentDate);
    projectedGraduationDate = cal.add(Calendar.YEAR, 4);
}

The value that I am trying to add years to is "enrollmentDate"

Is this possible, the "setTime" method accepts a "Date" time, not a GregorianCalendar though.

Was it helpful?

Solution 2

public setProjectedGraduationDate(GregorianCalendar projectedGraduationDate){
    projectedGraduationDate.setTime(this.enrollmentDate);
    projectedGraduationDate.add(Calendar.YEAR, 4);
}

OTHER TIPS

just execute getTime() to get Date instance out of GregorianCalendar

The add method of the GregorianCalendar class is void, so you can't assign a call to it to a variable.

If your intention is to modify the GregorianCalendar object that you're passing in to your method, then you'd want to write

projectedGraduationDate.add(calendar.YEAR,4);

but this would require setting projectedGraduationDate to the right value first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top