objective-c - 日期验证

标签 objective-c cocoa-touch ios date-comparison

我有两个文本字段。在这些文本字段中,我从选择器中获取以下格式的日期:“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/

相关文章:

objective-c - 从子类 WebView 更改 Window 的元素可见性

objective-c - 如何在iPhone中更改UITextField的颜色?

iphone - cocoa 方法返回当前语言环境字母表中所有字母的列表?

ios - 状态栏在模拟指标中改变颜色 swift ios

c# - 在 MonoMac 中使用数组的正确方法

iphone:无法连接 socket ?

ios - 需要帮助设置后台托管对象上下文。在 FRC controllerDidChangeContent 上获取异常

iOS 8 JavaScript 到 UIWebView 的通信错误

ios - 单击按钮时在 tableViewCell 中配置数据

带有 3 个标签的 iOS 水平 UIStackView - 第一个标签将其他标签推到视线之外