iPhone:如何在两个选定日期之间找到日期?

Dev*_*ang 0 iphone cocoa-touch objective-c nsdate ios4

在我的应用程序中,我有两个约会.

例如,

第1日:2011年10月28日

第二次约会:2011年11月2日

现在我想要在这两个选定日期之间的所有日期.

应该如此,

2011-10-28

29-10-2011

30-10-2011

2011年1月11日

2011年2月11日

如何使用NSDate获取此信息?

tho*_*mas 6

尝试 dateWithTimeInterval:SinceDate:

NSMutableArray dates = [NSMutableArray array];
NSDate *curDate = startDate;
while([curDate timeIntervalSince1970] <= [endDate timeIntervalSince1970]) //you can also use the earlier-method
{
    [dates addObject:curDate];
    curDate = [MSDate dateWithTimeInterval:86400 sinceDate:curDate]; 86400 = 60*60*24
}
//here maybe an additional check if the enddate has to be inserted or not
Run Code Online (Sandbox Code Playgroud)