之间比较2 NSDate的
答
阅读Date and Time Programming Guide很多的日期&时间概念(以及如何处理可可他们)进行了详细的解释在这里,真的很值得一读。
另外,在用于比较两个日期的所有方法的NSDate class Reference, you can find a dedicated section“比较日期”。所以,你应该用laterDate:
或earlierDate:
方法是完全回答你的问题。您也可以使用timeIntervalSinceDate:
方法和检查返回的时间间隔的符号(再一次看到这个文档)
一般情况下,不要犹豫,阅读文档为一切已经解释在那里详细,你可以看到给出的链接
答
去这个链接:
其他明智的转换你的约会增加一倍,并进行比较。所有相关的功能都在这个环节。
答
您可以使用NSDate's compare
method。例如:
switch ([dateOne compare:dateTwo]) {
case NSOrderedAscending:
// dateOne is earlier in time than dateTwo
break;
case NSOrderedSame:
// The dates are the same
break;
case NSOrderedDescending:
// dateOne is later in time than dateTwo
break;
}
答
NSDate* earlierDate = [aDate earlierDate:anotherDate];
返回值 接收器和anotherDate的早期,使用timeIntervalSinceDate确定:。如果接收方和anotherDate表示相同的日期,则返回接收方。