我正在开发一个appplication,其中我需要时间戳。我有两个包含小时,分钟和秒的字符串对象的数组,我需要减去它们并将它们作为小时,分钟和秒作为三个对象放在第三个数组中。 / p>
示例:
arr1=[9,10,22]
arr2=[10,12,42];
所以答案应该是
arr3=[1,2,22]
我需要将这个数组对象放在由' :'
请帮助。
答案 0 :(得分:0)
尝试这个
NSMutableArray * arr3=[[NSMutableArray alloc]init];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:0]integerValue]-[[arr1 objectAtIndex:0]integerValue]]];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:1]integerValue]-[[arr1 objectAtIndex:1]integerValue]]];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:2]integerValue]-[[arr1 objectAtIndex:2]integerValue]]];
答案 1 :(得分:0)
你也可以试试这个:
NSMutableArray *arr3=[[NSMutableArray alloc]init];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:0]intValue]-[[arr1 objectAtIndex:0]intValue]]];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:1]intValue]-[[arr1 objectAtIndex:1]intValue]]];
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:2]intValue]-[[arr1 objectAtIndex:2]intValue]]];
答案 2 :(得分:0)
试试这个:
NSMutableArray *arr3 = [NSMutableArray alloc]init];
for(int i=0;i<[arr1 count];i++)
{
[arr3 addObject:[NSString stringWithFormat:@"%d",[[arr2 objectAtIndex:i]integerValue]-[[arr1 objectAtIndex:i]integerValue]]];
}
NSString *combinedStr = [arr3 componentsJoinedByString:@":"];