iOS 当前月的天数

- (void)getSelectDate:(NSString *)day horse:(NSString *)horse minute:(NSString *)minute{

    MYLog(@"%@,%@,%@",day,horse,minute);

    //获取这个月的天数

    NSDate *today = [NSDate date];

    NSCalendar *c = [NSCalendar currentCalendar];

    NSRange days = [c rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:today];

    NSLog(@"%lu,%lu",(unsigned long)days.length,(unsigned long)days.location);


   //获取当前时间

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

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

    NSString *currentOlderOneDateStr = [dateFormatter stringFromDate:today];

    MYLog(@"%@",currentOlderOneDateStr);

    NSArray *time = [currentOlderOneDateStr componentsSeparatedByString:@"-"];

    

    //获取时间控件

    NSIndexPath *path = [NSIndexPath indexPathForRow:1 inSection:0];

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];

    

    if ([day isEqualToString:@"今天"]) {

        //判断小时

        if ([horse integerValue] <[time[3] integerValue]) {

            [self showToastHUDView:@"请选择对的日期" afterDelay:2];

            cell.detailTextLabel.text = @"";

            return;

        }else if ([horse integerValue] == [time[3] integerValue] ) {

            

            if ([time[4] integerValue]<30 && ([time[4] integerValue]+30)<=[minute integerValue]) {

                MYLog(@"%@,%@",time[4],minute);

                 cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%@-%@ %@:%@",time[0],time[1],time[2],horse,minute];

            }else{

             MYLog(@"%@,%@",time[4],minute);

                [self showToastHUDView:@"时间间隔太短" afterDelay:2];

                cell.detailTextLabel.text = @"";

                return;

            }

        }else{

          cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%@-%@ %@:%@",time[0],time[1],time[2],horse,minute];

        }

        

       

    

        

    }else if([day isEqualToString:@"明天"]){

        

        //判断年月日是否有进位

        NSInteger nextDay = [time[2] integerValue];

        NSInteger nextMoth = [time[1] integerValue];

        if (day.length < nextDay+1) {

            NSInteger nextAddOne = nextMoth +1;

            if (nextAddOne>12) {

                NSInteger years = [time[0] integerValue];

                cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld-%@-%@ %@:%@",(years+1),@"1",@"1",horse,minute];

            }else{

            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%ld-%@ %@:%@",time[0],(long)nextAddOne,@"1",horse,minute];

            }

        }else{

            NSInteger day =[time[2] integerValue];

            cell.detailTextLabel.text =  [NSString stringWithFormat:@"%@-%@-%ld %@:%@",time[0],time[1],(day+1),horse,minute];

        }

   

        

    }else if([day isEqualToString:@"后天"]){

    

        //判断年月日是否有进位

        NSInteger nextDay = [time[2] integerValue];

        NSInteger nextMoth = [time[1] integerValue];

        if ((day.length < nextDay+2)&&day.length != nextDay) {

            NSInteger nextAddOne = nextMoth +1;

            if (nextAddOne>12) {

                

                NSInteger years = [time[0] integerValue];

                cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld-%@-%@ %@:%@",(years+1),@"1",@"1",horse,minute];

            }else{

                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%ld-%@ %@:%@",time[0],(long)nextAddOne,@"1",horse,minute];

            }

        }else{

            NSInteger day =[time[2] integerValue];

            cell.detailTextLabel.text =  [NSString stringWithFormat:@"%@-%@-%ld %@:%@",time[0],time[1],(day+2),horse,minute];

        }

        

        if ((day.length < nextDay+2)&&day.length == nextDay) {

            NSInteger nextAddOne = nextMoth +1;

            if (nextAddOne>12) {

                

                NSInteger years = [time[0] integerValue];

                cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld-%@-%@ %@:%@",(years+1),@"1",@"2",horse,minute];

            }else{

                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@-%ld-%@ %@:%@",time[0],(long)nextAddOne,@"2",horse,minute];

            }

        }else{

            NSInteger day =[time[2] integerValue];

            cell.detailTextLabel.text =  [NSString stringWithFormat:@"%@-%@-%ld %@:%@",time[0],time[1],(day+2),horse,minute];

        }


        

        

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值