美文网首页
ios 两个NSDate类型日期比较大小

ios 两个NSDate类型日期比较大小

作者: 肉肉要次肉 | 来源:发表于2020-05-14 17:06 被阅读0次

+ (int)compareOneDay:(NSDate*)oneDaywithAnotherDay:(NSDate*)anotherDay{

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

    [dateFormattersetDateFormat:@"yy-MM-dd HH:mm"];

    NSString*oneDayStr = [dateFormatterstringFromDate:oneDay];

    NSString*anotherDayStr = [dateFormatterstringFromDate:anotherDay];

    NSDate*dateA = [dateFormatterdateFromString:oneDayStr];

    NSDate*dateB = [dateFormatterdateFromString:anotherDayStr];

    NSComparisonResultresult = [dateAcompare:dateB];

    if(result ==NSOrderedDescending) {

        //在指定时间前面 过了指定时间 过期

        return1;

    }elseif(result ==NSOrderedAscending){

        //没过指定时间 没过期

        //NSLog(@"Date1 is in the past");

        return-1;

    }

    //刚好时间一样.

    //NSLog(@"Both dates are the same");

    return0;

}

调用:int num = [ToolPublic compareOneDay:current withAnotherDay:fiDate];

相关文章

网友评论

      本文标题:ios 两个NSDate类型日期比较大小

      本文链接:https://www.haomeiwen.com/subject/ibfxohtx.html