我想比较两个日期之间的差异,但是在下面的代码中,我得到了错误“[NSCFString timeIntervalSinceReferenceDate]:无法识别的选择器发送到实例”。代码有什么问题?
NSDate *dateAdded=[eventDictionary objectForKey:@"dateAdded"];
NSDate *validUntilDate=[eventDictionary objectForKey:@"validUntilDate"];
NSDateComponents *sometimeAgo = [[NSCalendar currentCalendar] components:(NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:dateAdded toDate:validUntilDate options:0];
最佳答案
看来dateAdded
和/或validUntilDate
实际上是字符串,而不是日期。也许它们是代表日期的字符串,但毕竟是字符串。
关于ios - [NSCFString timeIntervalSinceReferenceDate] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6479421/