如何检查NSDate是否发生在其他两个NSDate之间 [英] How to Check if an NSDate occurs between two other NSDates
本文介绍了如何检查NSDate是否发生在其他两个NSDate之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用NSDate来判断当前日期是否在日期范围内。
I am trying to figure out whether or not the current date falls within a date range using NSDate.
例如,您可以获取当前日期/时间NSDate:
For example, you can get the current date/time using NSDate:
NSDate rightNow = [NSDate date];
然后我想使用该日期检查它是否在 9AM - 5PM 。
I would then like to use that date to check if it is in the range of 9AM - 5PM.
推荐答案
我想出了一个解决方案。
I came up with a solution. If you have a better solution, feel free to leave it and I will mark it as correct.
+ (BOOL)date:(NSDate*)date isBetweenDate:(NSDate*)beginDate andDate:(NSDate*)endDate
{
if ([date compare:beginDate] == NSOrderedAscending)
return NO;
if ([date compare:endDate] == NSOrderedDescending)
return NO;
return YES;
}
这篇关于如何检查NSDate是否发生在其他两个NSDate之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文