开发者

[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance

开发者 https://www.devze.com 2023-03-15 04:46 出处:网络
I would like to compare difference between two dates, but with the code below I got the error \"[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance.\" What\'s wrong wit

I would like to compare difference between two dates, but with the code below I got the error "[NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance." What's wrong with the code?

NSDate *dateAdded=[eventDictionary objectForKey:@"dateAdded"];
NSDate *validUntilDate=[eventDictionary objectForKey:@"validUntilDate"];
NSDateComponents *sometimeAg开发者_高级运维o = [[NSCalendar currentCalendar] components:(NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:dateAdded  toDate:validUntilDate  options:0]; 


It looks like dateAdded and/or validUntilDate are actually strings and not dates. Maybe they are strings representing dates, but strings after all.


You need to use an NSDateFormatter to convert your date strings to actual NSDates.

0

精彩评论

暂无评论...
验证码 换一张
取 消