iOS NSDate比较两个时间的大小

比较两个时间的大小

    NSString *content = [textField text];

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    NSTimeZone *timeZone = [NSTimeZone localTimeZone];

    [formatter setTimeZone:timeZone];

    [formatter setDateFormat : @"yyyy-MM-dd"];

    NSDate *nowDate = [formatter dateFromString:newStr];

    NSDate *writeDate = [formatter dateFromString:content];

    NSComparisonResult result = [nowDate compare:writeDate];

    NSLog(@"the result---%ld",(long)result);

    if (result == -1) {

        NSLog(@"today later!!");

    }else if (result == 1){

        NSLog(@"today before!!");

    }else{

        NSLog(@"time is today!!");

    }

你可能感兴趣的:(iOS NSDate比较两个时间的大小)