Why can't NSDate be compared using < or>?

前端 未结 4 1177
無奈伤痛
無奈伤痛 2021-01-14 09:48
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@\"MM/dd/yyyy\"];
NSLog([@\"today is \" stringBy         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 09:56

        if ([date compare:firstBirthdayDate] == NSOrderedAscending){
             NSLog(@"First date is earlier than today");
        }
       else{
            NSLog(@"First date is later than today");
       }
       if ([date compare:secondBirthdayDate] == NSOrderedAscending){
             NSLog(@"Second date is earlier than today");
       }
    
       if ([firstBirthdayDate compare: secondBirthdayDate] == NSOrderedSame) 
            NSLog(@"First date is the same as second date");
    

提交回复
热议问题