How to normalize NSDate objects (i.e. set the time to midnight)

When you create new date using [NSDate date] (i.e. today, as in right now) your date will save the current time as well as its date.

In fact, under the hood an NSDate object is the amount of seconds that have elapsed since the 1st of January 2001 (or 1970), in milliseconds. So really it’s a massive floating point number. You can see what it is with this code:

This content is for members only.

In a nutshell, we “explode” the date into its year, month and day components, and then recreate a new object with these and no other components.





Leave a Reply