With the impending release of WatchKit the month this post was originally published, it seemed “timely” to talk about NSDate. Puns like this are going to keep on coming, Operator Overloading — Tailor Swift To Your Needs was only one of many, you have been warned.
An NSDate object specifies a particular point in time. Despite “date” being in its name, it really stores time, of which the date is a component. Under the hood, NSDates (as far as the public superclass we can see is concerned) are specified as a number of seconds past a reference date. NSDate’s reference date is the first moment of January 1, 2001 in the GMT timezone. These seconds are stored as a Double, which allows NSDate to range from milliseconds to years. What we see as an NSDate is actually an abstract public superclass for a cluster of classes related to dates. The internal classes are private, so talking about them here wouldn’t be particularly helpful, and it is probably best not to mess with them anyway.
If you need to save a timestamp for something in your iOS app, or maybe have a countdown timer for an app or game, you will be dealing with the NSDate class, so let’s take a look at it.