A representation of a specific point in time that bridges to
NSDate when you need reference semantics or other Foundation-specific behavior.
- iOS 2.0+
- macOS 10.0+
- UIKit for Mac 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
NSDate objects encapsulate a single point in time, independent of any particular calendrical system or time zone. Date objects are immutable, representing an invariant time interval relative to an absolute reference date (00:00:00 UTC on 1 January 2001).
NSDate class provides methods for comparing dates, calculating the time interval between two dates, and creating a new date from a time interval relative to another date.
NSDate objects can be used in conjunction with
Date objects to create localized representations of dates and times, as well as with
NSCalendar objects to perform calendar arithmetic.
You might subclass
NSDate in order to make it easier to work with a particular calendrical system, or to work with date and time values with a finer temporal granularity.
Methods to Override and Other Requirements
If you want to subclass
NSDate to obtain behavior different than that provided by the private or public subclasses, you must:
Declare a suitable instance variable to hold the date and time value (relative to an absolute reference date)
timeinstance method to provide the correct date and time value based on your instance variable
Interval Since Reference Date
init(time, one of the designated initializer methods
Interval Since Reference Date:)
If creating a subclass that represents a calendrical system, define methods that partition past and future periods into the units of this calendar
Your subclass may use a different reference date than the absolute reference date used by
NSDate (00:00:00 UTC on 1 January 2001). If it does, it must still use the absolute reference date in its implementations of the methods
init(time. That is, the reference date referred to in the titles of these methods is the absolute reference date. If you do not use the absolute reference date in these methods, comparisons between
NSDate objects of your subclass and
NSDate objects of a private subclass will not work.