Objective c 无法将字符串正确转换为日期目标c

Objective c 无法将字符串正确转换为日期目标c,objective-c,ios,cocoa,date,Objective C,Ios,Cocoa,Date,这是我的代码: - (NSArray *)getCurrentDayEvents { [dateFormat setDateFormat:@"dd/LL/YYYY"]; [currentDate retain]; NSString *todayStringDate = [dateFormat stringFromDate:currentDate]; return [eventiArray filteredArrayUsingPredicate:

这是我的代码:

- (NSArray *)getCurrentDayEvents {  
    [dateFormat setDateFormat:@"dd/LL/YYYY"];

    [currentDate retain];
    NSString *todayStringDate = [dateFormat stringFromDate:currentDate];

    return [eventiArray filteredArrayUsingPredicate:
            [NSPredicate predicateWithFormat:@"(inizio CONTAINS[cd] %@)", todayStringDate] ];
}
我可以将日期转换为字符串,但如果我添加以下内容:

NSDate *temp = [dateFormat dateFromString: todayStringDate];
我总是得到类似2010-12-26的东西。。。 我知道我在做一步2次

顺便说一句,我打印了currentdate,得到了这个值:

2011-11-17 23:00:00+0000


结果是不同的,因为您正在使用通用描述方法打印NSDate实例,该方法与您期望的输出格式不匹配。
让NSDate描述以您想要的格式返回字符串的唯一方法是使用类别或子类覆盖它。

试试[dateFormat setDateFormat:@“dd/MM/yyyy”];