打破时间相当于小时,ios?

时间:2015-01-27 09:22:08

标签: ios datetime nsmutablearray

我有一组时间字符串如下:

 Time-Array = {10:00 AM, 10:15 AM ,10:30 AM,10:45 AM,11:00 AM,11:15 AM,11:30 AM,11:45 AM,12:00 PM,

 3:00 PM,3:15 PM, 3:30 PM, 3:45 PM,4:00 PM,

 7:00 PM,7:15 PM, 7:30 PM. 7:45 PM, 8:00 PM, 8:15 PM, 8:30 PM, 8:45 PM, 9:00 PM, 9:15 PM, 9:30 PM, 9:45 PM, 10:00 PM}

我想将其分解为输出为:

的单一时间
10:00 AM - 12: 00 PM

3:00 PM - 4:00 PM

7:00 PM - 10: 00 PM

到目前为止,我已经尝试了

NSLog(@"------****%@",TTTimeArray);
        NSString *sss=[TTTimeArray objectAtIndex:0];
        int addTime=0;
        NSString *dateOutPut;
        NSLog(@"sss------****%@",sss);
        timeArray=[NSMutableArray array];
        for(int i=0;i<[TTTimeArray count]-1;i++)
        {
            if ([[TTTimeArray objectAtIndex:i] isEqualToString:sss]) {
                [timeArray addObject:[TTTimeArray objectAtIndex:i]];
                 NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
                [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
                [formatter setTimeZone:[NSTimeZone systemTimeZone]];
                [formatter setDateFormat:@"hh:mm a"];
                addTime=15;
                NSDate *dateInput=[formatter dateFromString:sss];
                dateInput=[dateInput dateByAddingTimeInterval:addTime*60];
                dateOutPut=[formatter stringFromDate:dateInput];
                dateOutPut=[dateOutPut uppercaseString];
                sss=dateOutPut;
                NSLog(@"OutputDate= %@",dateOutPut);

            }
            NSLog(@"iii------****%d",i);
 //                else if ([[TTTimeArray objectAtIndex:i] isEqualToString:sss]) {
//                    
//                }
         }

我能够在上午10:00到中午12:00。但在那之后我很困惑我接下来要做什么来获得下一个输出。

0 个答案:

没有答案