addYears()

Add the specified number of years to this date.

Syntax

public DtpDate addYears(int numberOfYears) 
 

Parameters

numberOfYears
An integer number. If it is a negative number, the new date will be the date that is numberOfYears years before the current DtpDate object.

Return values

A new DtpDate object.

Notes

The addYears() method adds the specified number of years to this date. You can then use the get() methods to retrieve the information of the resulting new date. The DtpDate returned inherits all the properties of the current instance of DtpDate, such as month names, date format, and so on.

Examples

DtpDate toDay = new DtpDate();
 DtpDate lastYear= toDay.addYears(-1);
 System.out.println("Next month is "
    + lastYear.getDayOfMonth() + "/"
    + lastYear.getNumericMonth() + "/" 
    + lastYear.getYear() + " "
    + lastYear.getHours() + ":" 
    + lastYear.getMinutes() + ":" 
    + lastYear.getSeconds());
 

See also

addDays(), addWeekdays()

Copyright IBM Corp. 2003