未编译——可能有一些 tupos。
NSDateFormatter* dayFmt = [[NSDateFormatter alloc] init];
[dayFmt setTimeZone:<whatever time zone you want>];
[dayFmt setDateFormat:@"g"];
NSInteger lastDay = [[dayFmt stringFromDate:startDate] integerValue];
// Note: We assume that myDates is sorted, as stated.
for (NSDate* myDate in myDates) {
NSInteger myDay = [[dayFmt stringFromDate:myDate] integerValue];
while (myDay > lastDay+1) {
lastDay++;
NSDate* newDate = [dayFmt dateFromString:[NSString stringWithFormat:@"%d", lastDay]];
[missingDates addObject:newDate];
}
}
(我将把它作为一个练习,让用户弄清楚如何填写最后一个数组条目和一些任意结束日期之间的任何缺失日期。)
(还应该注意,代码假设数组中没有重复的日期。很容易处理,但对用户来说是另一个练习。)