我试图强制用户选择一个日期在未来与日期选择器。我显然使用了compare方法,但是,当我执行下面的代码时,即使它与[NSDate date]的日期相同,它也会告诉执行if语句。这里是我的代码:比较NSDate [NSDate日期]
if ([datePicker.date compare:[NSDate date]] == NSOrderedAscending) // If the picked date is earlier than today
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hmm, this date is earlier than today"
message:@"The date you've selected is earlier than today's date, please pick another"
delegate:nil
cancelButtonTitle:@"Okay, I'll pick another"
otherButtonTitles:nil];
// Show the alert
[alert show];
// Release the alert
[alert release];
}
您是否尝试过使用'laterDate:'(或'earlierDate:')做比较? – gerry3 2010-02-13 19:25:20
如果你NSLog日期只是为了看看它是否有正确的值,会发生什么。 – 2010-02-13 19:43:10