Calendar.addMonths

Returns a new Time with the specified number of months added. If the months are negative, the months are subtracted.

If the target month does not support the day component of the input time, then an error will be thrown, unless truncateDay is set to true. If truncateDay is set to true, then the day is reduced to the maximum day of that month.

For example, adding one month to 1/31/2000 with truncateDay set to true results in 2/28/2000.

The default implementation uses information provided by the calendar to calculate the correct time to add. Derived classes may override if there is a more optimized method.

Note that the generic method does not take into account crossing era boundaries. Derived classes may support this.

class Calendar
Time
addMonths
(
Time t
,,
bool truncateDay = false
)

Parameters

nMonths int

The number of months to add. This can be negative.

truncateDay bool

Round the day down to the maximum day of the target month if necessary.

Return Value

Type: Time

A Time that represents the provided time with the number of months added.

Meta