判断当前时间和指定时间大小

NSString *stopTimeStr = [NSString stringWithFormat:@"%@",[infoData objectForKey:@"stoptime"]];


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

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

    NSString *dateTime=[formatter stringFromDate:[NSDate date]];

    NSDate *date = [formatter dateFromString:dateTime];


    NSDate *date2 = [formatter dateFromString:stopTimeStr];


    NSComparisonResult result = [date compare:date2];


if (result ==NSOrderedAscending) {

stoptime 大于当前时间

date2 >date

    }else if (result ==NSOrderedDescending ){

date2

stoptime 小于当前时间呢

    }

你可能感兴趣的:(判断当前时间和指定时间大小)