iphone - 检查当前时间是否在时间 A 和 B 之间

标签 iphone ios ipad time

无论如何我可以检查当前时间是否在两个时间之间?

当前时间 = 12:00 AM
时间 A:上午 8:00
时间 B:下午 3:00

这将返回 true,这不会:
当前时间:下午 1:00
A = 凌晨 1:00
B = 凌晨 2:00

最佳答案

您可以按照以下方式进行操作:

NSDate *timeA, *timeB; // Whatever and however you want to set these;
NSDate *now = [NSDate date];

If([now compare:timeA] == NSOrderedDescending && [now compare:timeB] == NSOrderedAscending)
    // then now is between timeA and Time B

关于iphone - 检查当前时间是否在时间 A 和 B 之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12238395/

相关文章:

ios - TestFlight:使用多个设备

iphone:不调用 didReceiveAuthenticationChallenge 和 canAuthenticateAgainstProtectionSpace 以提供安全的 Restful 服务

iphone - 如何分发已被 App Store 拒绝的 iOS 应用程序?

iphone - 如何将带有 iOS base SDK 6.1 的项目部署到带有 iOS 7 的设备

iphone - iphone 上的通用应用视网膜图像性能

iphone - 如何预览UIWebview打印?

c++ - 找不到可用的 C 编译器

objective-c - iOS8 在 iPad Air 上使用 HealthKit 时如何修复 "Health data is unavailable on this device"

iphone - 对核心数据中实体之间的属性进行计算

ios - 如何将应用程序从 iphone 迁移到 ipad?