[Solved] How to compare two given times with current time? [duplicate]


Comparing 2 NSDates.

    ...
    NSDate *date1= [formatter dateFromString:time1];
    NSDate *date2 = [formatter dateFromString:time2];

    if ([date2 compare:date1] == NSOrderedDescending) {
        NSLog(@"date1 is later than date2");

    } else if ([date2 compare:date1] == NSOrderedAscending) {
        NSLog(@"date1 is earlier than date2");

    } else {
        NSLog(@"dates are the same");

    }

UPD:
via Switch

       ...
        NSDate *date1= [formatter dateFromString:time1];
        NSDate *date2 = [formatter dateFromString:time2];

        NSComparisonResult result = [date2 compare:date1];
        switch(result){
            case NSOrderedDescending:
                NSLog(@"date1 is later than date2");
                break;
            case NSOrderedAscending:
                NSLog(@"date1 is earlier than date2");
                break;
            default:
                NSLog(@"dates are the same");
                break;
         }

3

solved How to compare two given times with current time? [duplicate]