不,您必须自己创建半月计算。只是为了好玩,我为你写了以下内容。享受。
- (NSArray *)createPaymentScheduleWithStartDate:(NSDate *)startDate numberOfPayments:(NSUInteger)payments {
NSUInteger count = 0;
NSCalendar *cal = [NSCalendar currentCalendar];
NSMutableArray *schedule = [NSMutableArray arrayWithCapacity:payments];
// break down the start date for our future payments
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit
| NSTimeZoneCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *comps = [cal components:unitFlags fromDate:startDate];
NSInteger month = [comps month];
NSInteger day = [comps day];
NSInteger year = [comps year];
// For simplicity sake, adjust day larger than 28
// this way we don't have to test each time we create a date
// if it valid.
if (day > 28)
day = 28;
// NSDate *a = startDate;
// because we want all payments to have the same time
// create the first again
NSDate *a = [cal dateFromComponents:comps];
do {
month++;
if (month > 12) {
year++;
month = 1;
}
// create the next month payment date
comps.month = month;
comps.day = day;
comps.year = year;
NSDate *b = [cal dateFromComponents:comps];
// find the middle date
NSTimeInterval m = [b timeIntervalSinceDate:a];
NSDate *c = [a dateByAddingTimeInterval:m / 2];
// add dates to our schedule array
[schedule addObject:a];
[schedule addObject:c];
count += 2;
// adjust to next group of payments
a = b;
} while (count < (payments + 5));
// because we add two payments at a time,
// we have to adjust that extra payment
if ([schedule count] > payments) {
// create range of our excess payments
NSRange range = NSMakeRange(payments, [schedule count] - payments);
[schedule removeObjectsInRange:range];
}
NSLog(@"Schedule: %@", schedule);
return [NSArray arrayWithArray:schedule];
}