可能重复:
Comparing dates
How to compare two dates in Objective-C如何在Objective-C两个字符串比较
我想比较两个字符串谁有一个日期格式“2011年11月6日例如“和”12-06-2011“为例。 我想看看第二个日期是否大于第一个或不是 你能帮助我吗?
我想这码
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-YYYY"];
NSDate *date1 = [dateFormat dateFromString:deparatureDateField.text];
NSDate *date2 = [dateFormat dateFromString:comebackDateField.text];
[dateFormat release];
NSTimeInterval timeInterval = [date1 timeIntervalSinceDate:date2];
if(timeInterval >= 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"come back date should be greater" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[alert show];
}
但我ALWAYSE有一个警报,NSTimeInterval一个时间间隔是ALWAYSE NULL
@Regexident @murat thakyou但我想我的问题不清楚。我不想看看是否有平等的,我想看看第二个日期是否大于第一个日期 – user794317 2011-06-11 22:36:19
@ user794317:更新了我的答案。看第二个片段。 – Regexident 2011-06-11 22:44:49
@Regexident非常感谢你,但我总是有麻烦,我更新了我的问题 – user794317 2011-06-11 23:33:22