Instance Method

dateByAddingUnit:value:toDate:options:

Returns a date representing the absolute time calculated by adding the value of a given component to a given date.

Declaration

- (NSDate *)dateByAddingUnit:(NSCalendarUnit)unit value:(NSInteger)value toDate:(NSDate *)date options:(NSCalendarOptions)options;

Parameters

unit

The unit to use for the calculation. For possible values, see NSCalendarUnit.

value

The value for the given unit.

date

The date to use to perform the calculation.

options

Options for the calculation. See NSCalendarOptions for possible values.

If you specify a “wrap” option (NSCalendarWrapComponents), the specified components are incremented and wrap around to zero/one on overflow, but do not cause higher units to be incremented. When the wrap option is false, overflow in a unit carries into the higher units, as in typical addition.

Return Value

A new NSDate object representing the absolute time calculated by adding to date the value of the given calendrical unit using the options specified by options. Returns nil if date falls outside the defined range of the receiver or if the computation cannot be performed.

See Also

Calculating Dates

- dateFromComponents:

Returns a date representing the absolute time calculated from given components.

- dateByAddingComponents:toDate:options:

Returns a date representing the absolute time calculated by adding given components to a given date.

- dateBySettingHour:minute:second:ofDate:options:

Creates a new date calculated with the given time.

- dateBySettingUnit:value:ofDate:options:

Returns a new date representing the date calculated by setting a specific component of a given date to a given value, while trying to keep lower components the same.

- dateWithEra:year:month:day:hour:minute:second:nanosecond:

Returns a date created with the given components.

- dateWithEra:yearForWeekOfYear:weekOfYear:weekday:hour:minute:second:nanosecond:

Returns a new date created with the given components base on a week-of-year value.

- nextWeekendStartDate:interval:options:afterDate:

Returns by reference the starting date and time interval range of the next weekend period after a given date.