我有两个文本字段。在这些文本字段中,我从选择器中获取以下格式的日期:“mm-dd-yyyy”。我想要做的是验证从一个文本字段到另一个文本字段的日期,以便两个文本字段不会填充相同的日期,并且第一个文本字段的日期始终大于第二个文本字段的日期。谁能解释一下如何在 iPhone 上执行此操作?
最佳答案
您可以使用[NSDate比较:];
From documentation
compare
:Returns an
NSComparisonResult
value that indicates the temporal ordering of the receiver and another given date.
- (NSComparisonResult)compare:(NSDate *)anotherDate
Parameters
anotherDate
The date with which to compare the receiver. This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X.
Return Value
If:
The receiver and anotherDate are exactly equal to each other, NSOrderedSame
The receiver is later in time than anotherDate, NSOrderedDescending
The receiver is earlier in time than anotherDate, NSOrderedAscending.
关于objective-c - 日期验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5907926/