iOS开发:日期比较大小

//日期比较大小

-(NSInteger)compareDate:(NSString*)startDate withDate:(NSString*)endDate btnTitle:(NSString*)btnTitle

{

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

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

    [dateformatersetDateFormat:@"HH:mm"];

    NSDate*start = [[NSDatealloc]init];

    NSDate*end = [[NSDatealloc]init];


    start = [dateformaterdateFromString:startDate];

    end  = [dateformaterdateFromString:endDate];

    NSComparisonResultresult = [startcompare:end];

    if(result==NSOrderedSame)

    {

        // 相等

        [SVProgressHUD setMinimumDismissTimeInterval:1.0f];

        [SVProgressHUD showErrorWithStatus:@"起始日期不能相同!"];

    }else if (result==NSOrderedAscending)

    {

        //endDate比startDate大

        [self.endBtn setTitle:btnTitle forState:UIControlStateNormal];

    }else if (result==NSOrderedDescending)

    {

        //endDate比startDate小

        [SVProgressHUD setMinimumDismissTimeInterval:1.0f];

        [SVProgressHUD showErrorWithStatus:@"结束日期不能小于开始时间!"];

    }

    return result;

}

你可能感兴趣的:(iOS开发:日期比较大小)