Time.addYears

Overview | Methods | Fields | This Package | All Packages

Time.addYears

Creates a new Time object that represents the number of years after the time that this Time object represents.

Syntax

public Time addYears( int interval )

Parameters

interval

An integer value that represents the number of years to add to the current time.

Return Value

Returns a Time object representing the new time.

Remarks

Time objects cannot be altered. Use the addYears method to create a new Time object whose date is based on the current Time object but incremented by the number of years specified in interval.

Example

The following example illustrates how to use the addYears method to create a new Time object that is six years later in time than a Time object that is initialized to the current time:

public int ReturnMastersYear()
{
	//Create object that is set to current date
	Time startCollege = new Time();
		
	//Increment startCollege by 6 years
	Time endMasters = startCollege.addYears(6);
	//Output the date
	return endMasters.getYear();
}

See Also   getYear, addDays, addMonths