How to check if an NSDate
belongs to today?
I used to check it using first 10 characters from [aDate description]
. [[aDate descriptio
In macOS 10.9+ & iOS 8+, there's a method on NSCalendar/Calendar that does exactly this!
- (BOOL)isDateInToday:(NSDate *)date
So you'd simply do
Objective-C:
BOOL today = [[NSCalendar currentCalendar] isDateInToday:date];
Swift 3:
let today = Calendar.current.isDateInToday(date)
Check our Erica Sadun's great NSDate extension
. Very simple to use. Fine it here:
http://github.com/erica/NSDate-Extensions
It's already there in this post: https://stackoverflow.com/a/4052798/362310