我是新來的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