0

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

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

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

4

1 回答 1

3

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

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
于 2012-09-02T22:40:25.627 回答