Contents

NSDateInterval

An object representing the span of time between a specific start date and end date.

Declaration

class NSDateInterval

Overview

In Swift, this object bridges to DateInterval; use NSDateInterval when you need reference semantics or other Foundation-specific behavior.

An NSDateInterval object represents a closed interval between two dates. The NSDateInterval class provides a programmatic interface for calculating the duration of a time interval and determining whether a date falls within it, as well as comparing date intervals and checking to see whether they intersect.

An NSDateInterval object consists of a startDate and an endDate. The startDate and endDate of a date interval can be equal, in which case its duration is 0. However, endDate cannot occur earlier than startDate.

You can use the DateIntervalFormatter class to create string representations of NSDateInterval objects that are suitable for display in the current locale.

Topics

Creating Date Intervals

Accessing Start Date, End Date, and Duration

Comparing Date Intervals

Determining Intersections

Determining Whether a Date Occurs Within a Date Interval

Initializers