比较两个NSDate

系统自带的NSDate比较会比较深,比较到秒的量级,但是我们有时候想只比较日期,没有时间,看下面:

- (BOOL)isTheSameDate:(NSDate *)date AnotherDate:(NSDate *)anotherDate
{
    if (date == nil || anotherDate == nil) return NO;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy"];
    NSString *strDate = [dateFormatter stringFromDate:date];
    NSString *strAnotherDate = [dateFormatter stringFromDate:anotherDate];
    NSDate *dateA = [dateFormatter dateFromString:strDate];
    NSDate *dateB = [dateFormatter dateFromString:strAnotherDate];
    if ([dateA isEqualToDate:dateB]) {
        return YES;
    } else {
        return NO;
    }
}

 

 
posted @ 2015-05-21 18:32  Shreker  阅读(246)  评论(0编辑  收藏  举报