我有一个数组,它包含日期字符串。我想要比较日期字符串,并将日期字符串显示为分组,因此当发现重复日期时,它应该只显示一次日期。
我的数组
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:@"2010-12-28 04:23:47",
@"2010-12-28 04:21:50",
@"2010-12-28 04:18:56",
@"2010-12-27 13:39:18",
@"2010-12-22 21:48:09",
@"2010-12-22 20:44:18",
@"2010-12-22 20:25:26",
@"2010-12-22 20:08:39",nil];预期输出是,
"2010-12-28 "
"2010-12-27 "
"2010-12-22 ".当与日期字符串进行比较时,时间不是问题,我只想显示日期(分组日期)。
请帮帮我。
谢谢。
发布于 2010-12-28 22:17:49
代码如下:
NSMutableArray *filterdArray=[[NSMutableArray alloc]init];
for(NSString *string in arr)
{
NSArray *components = [string componentsSeparatedByString: @" "];
//Check that date is present in filterdArray
//if not present
//add the value to array using
[filterdArray addObject:[components objectAtIndex:0]];
}然后对filterdArray中的值进行排序
https://stackoverflow.com/questions/4546649
复制相似问题