我正在尝试将我从 Web 服务收到的 NSDate 拆分为两个不同的日期,以便为每天包含部分的事件填充 tableView。我认为执行后者的最简单的方法是创建一个 fetch 请求来寻找独特的日子。
所以我尝试创建一个 NSDate“日”,但将时间组件设置为 00:00。我想知道是否有更有效的方法来实现这一点:
if (eventoItemList.count > 0) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
[dayFormatter setDateFormat:@"yyyy-MM-dd"];
for (GDataXMLElement *eventoItem in eventoItemList) {
BOEvent *event = [[BOEvent alloc] init];
NSString *idEventStr = [[[eventoItem elementsForName:@"id"] objectAtIndex:0] stringValue];
NSString *name = [[[eventoItem elementsForName:@"titulo"] objectAtIndex:0] stringValue];
NSString *type = [[[eventoItem elementsForName:@"tipo"] objectAtIndex:0] stringValue];
NSString *descr = [[[eventoItem elementsForName:@"descripcion"] objectAtIndex:0] stringValue];
NSString *address = [[[eventoItem elementsForName:@"direccion"] objectAtIndex:0] stringValue];
NSDate *date = [dateFormatter dateFromString:[[[eventoItem elementsForName:@"fecha"] objectAtIndex:0] stringValue]];
NSString *action = [[[eventoItem elementsForName:@"accion"] objectAtIndex:0] stringValue];
[event setIdEvent:[idEventStr integerValue]];
[event setName:name];
[event setType:type];
[event setDesc:descr];
[event setAddress:address];
[event setAction:action];
[event setDate:date];
[event setDayDate:[dayFormatter dateFromString:[dayFormatter stringFromDate:date]]];
[events addObject:event];
}
}
谢谢您的帮助。