Microsoft SDK for Java

Time.addMonths

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

Syntax

public Time addMonths( int interval )

Parameters

interval

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

Return Value

Returns a Time object representing the new time.

Remarks

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

Example

The following example illustrates how to use the addMonths method to create a new Time object that is three months later in time than a Time object that is initialized to New Year's Day 1999:

public String ReturnFirstQuarter()
{
   //Create object that is set to the beginning of 1999
   Time newYears = new Time(1999,01,01);
      
   //Increment newyears by 3 months
   Time firstQuarter = newYears.addMonths(3);
   //Output the date
   return firstQuarter.formatLongDate();
}

See Also   formatLongDate, addDays, addYears

© 1999 Microsoft Corporation. All rights reserved. Terms of use.