Contents

date(byAdding:value:to:options:)

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

Declaration

func date(byAdding unit: NSCalendar.Unit, value: Int, to date: Date, options: NSCalendar.Options = []) -> Date?

Parameters

  • unit:

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

  • value:

    The value for the given unit.

  • date:

    The date to use to perform the calculation.

  • options:

    Options for the calculation. See Options for possible values.

    If you specify a “wrap” option (Wrapcomponents), 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