我是新来的iPhone开发者,比较两个NSDates在iPhone
我想比较两个日期,第一次约会将来自数据库让说,newDate
和第二个是今天的日期,
如果今天是更大然后newDate
然后我想显示警报。
这里是我的代码片段,
NSString *newDate = [formatter stringFromDate:st];
NSDate *today=[[NSDate alloc]init];
if ([today compare:newDate] == NSOrderedDescending)
{
NSLog(@"today is later than newDate");
}
else if ([today compare:newDate] == NSOrderedAscending)
{
NSLog(@"today is earlier than newDate");
}
else
{
NSLog(@"dates are the same");
}
,但它崩溃,并且在编译这也说明我在这里警告[today compare:newDate]
任何帮助将不胜感激。
这会帮助你: http://stackoverflow.com/questions/5965044/how-to-compare-two-nsdates-which-is-more-recent – 2012-07-10 12:02:20
什么是警告说,对'[今天比较:newDate]'?也许这个警告应该给你一个线索? – 2012-07-10 12:07:15