An object that specifies a date or time in terms of units (such as year, month, day, hour, and minute) to be evaluated in a calendar system and time zone.
- iOS 2.0+
- macOS 10.4+
- tvOS 9.0+
- watchOS 2.0+
NSDate encapsulates the components of a date in an extendable, object-oriented manner. It's used to specify a date by providing the temporal components that make up a date and time: hour, minutes, seconds, day, month, year, and so on. You can also use it to specify a duration of time, for example, 5 hours and 16 minutes. An
NSDate object is not required to define all the component fields. When a new instance of
NSDate is created, the date components are set to
An instance of
NSDate is not responsible for answering questions about a date beyond the information with which it was initialized. For example, if you initialize one with May 4, 2017, its weekday is
NSDate, not Thursday. To get the correct day of the week, you must create a suitable instance of
NSCalendar, create an
NSDate object using
date and then use
components: to retrieve the weekday—as illustrated in the following example.