Could someone please help me figure out how to check if some date is of the same day as today. I guess it would require creating a calender day at 0 hour of the same day in the same timezone and checking against that, but so far my attempts have confused me more then anything.
NSCalendar lets you deal with human days. So you could implement a category something like this:
@implementation NSDate (IsItToday)
- (BOOL)isToday {
    NSUInteger desiredComponents = NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit;
    NSDateComponents *myCalendarDate = [[NSCalendar currentCalendar] components:desiredComponents fromDate:self];
    NSDateComponents *today = [[NSCalendar currentCalendar] components:desiredComponents fromDate:[NSDate date]];
    return [myCalendarDate isEqual:today];
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With