【ios】判断日期是今天

    NSDate *currentDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:currentDate];

    NSDate *today = [calendar dateFromComponents:components];

    components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:self.birthday];

    NSDate *otherDate = [calendar dateFromComponents:components];

    if([today isEqualToDate:otherDate]) {

      NSLog(@"today");

    }

 

posted @ 2016-05-23 14:10  kaysun5230  阅读(659)  评论(0编辑  收藏  举报