Created
May 14, 2012 21:35
-
-
Save batosai/2697373 to your computer and use it in GitHub Desktop.
Check if date is now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample | |
NSDate *myDate = [[NSDate alloc] initWithString:@"Some date string"]; | |
if ([[NSDate date] isSameDay:myDate]) { | |
NSLog(@"Today"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSDate (date) | |
- (BOOL)isSameDay:(NSDate*)anotherDate; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSDate.h" | |
@implementation NSDate (date) | |
- (BOOL)isSameDay:(NSDate*)anotherDate | |
{ | |
NSCalendar* calendar = [NSCalendar currentCalendar]; | |
NSDateComponents* components1 = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:self]; | |
NSDateComponents* components2 = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:anotherDate]; | |
return ([components1 year] == [components2 year] && [components1 month] == [components2 month] && [components1 day] == [components2 day]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment