2012-07-13 71 views
0

我有生日列表。从b'days列表中,我需要选择在未来30天内发生的所有b'days。NSDate比较

例如:今天的日期是07/13,那么我需要列出07/13和08/13之间发生的所有b'days。

是否有任何内置的方法来选择这种方式的日期。

在此先感谢

+0

没有内置方法对于这一点,但是你的逻辑和文档,对不对? – 2012-07-13 05:31:06

+0

[如何检查两个其他NSDates之间是否发生NSDate]的可能重复(http://stackoverflow.com/questions/1072848/how-to-check-if-an-nsdate-occurs-between-two-other- nsdates) – marcog 2012-07-13 05:38:33

回答

2

您可以使用此NSPredicate

NSDate *now = [NSDate date]; 
NSDate *later = [now dateByAddingTimeInterval:(30*24*60*60)]; 
NSPredicate *pre = [NSPredicate predicateWithFormat:@"SELF >= %@ AND SELF <= %@", now, later]; 
NSArray *upcomingBirthdays = [birthdays filteredArrayUsingPredicate:pre]; 
0

你将不得不工作的逻辑为自己,这里是一个链接到“日期和时间编程指南”。它包含一些示例代码来检查“日期”是否在一周内。可能是一个开始的好地方。

Apple's guide

+0

谢谢你日期。我会看看。 – 2012-07-13 05:43:29