ios - 检测时间是否以小时为单位的简单方法是什么?

标签 ios objective-c iphone uidatepicker nstimeinterval

我在我的项目中使用 UIDatePickerViewtimeInterval 一分钟。选择时间后,如果时间以小时为单位,那么我必须做一些事情。那么我如何检测用户是否选择了以小时为单位的时间?

最佳答案

Try this one , you can get hours between two date.

NSDate* date1 = someDate;
 NSDate* date2 = someOtherDate;
 NSTimeInterval distanceBetweenDates = [date1 timeIntervalSinceDate:date2];
 double secondsInAnHour = 3600;
 NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;

关于ios - 检测时间是否以小时为单位的简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38865058/

相关文章:

android - 将 google play/apple store 自动续订订阅与内部帐户同步的预期行为是什么?

iphone - 购买时重复方法

ios - 在 Swift iOS 中将文本字段设置为应用程序启动时的第一响应者

ios - 替换 CLLocationManager 的 "purpose"属性

ios - ios 8 中的 voip 应用程序是否有新要求?

iphone - 让对象在从 super View 中删除后发送自己的委托(delegate)消息

iphone - 我应该直接连接到 CouchDB 的套接字并传递 HTTP 请求还是使用 node.js 作为代理?

ios - 测试字典数组中是否存在具有特定属性的对象

iphone - 从 nib 文件加载 View 时对其进行动画处理

iOS 8 : How to implement a rotating view controller on top of a portrait-only app?