あなたはほとんどそれを手に入れました。いくつかの変更のみ:
int numberOfDays=30;
NSDate *startDate=[NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *offset = [[NSDateComponents alloc] init];
NSMutableArray* dates = [NSMutableArray arrayWithObject:startDate];
for (int i = 1; i < numberOfDays; i++) {
[offset setDay:i];
NSDate *nextDay = [calendar dateByAddingComponents:offset toDate:startDate options:0];
[dates addObject:nextDay];
}
[offset release];
NSLog(@"%@",dates);
これにより、オブジェクトの配列が作成されNSDate
ます。私のマシンでは、次のログが記録されます。
EmptyFoundation[4302:903] (
"2011-02-16 16:16:26 -0800",
"2011-02-17 16:16:26 -0800",
"2011-02-18 16:16:26 -0800",
"2011-02-19 16:16:26 -0800",
"2011-02-20 16:16:26 -0800",
"2011-02-21 16:16:26 -0800",
"2011-02-22 16:16:26 -0800",
"2011-02-23 16:16:26 -0800",
"2011-02-24 16:16:26 -0800",
"2011-02-25 16:16:26 -0800",
"2011-02-26 16:16:26 -0800",
"2011-02-27 16:16:26 -0800",
"2011-02-28 16:16:26 -0800",
"2011-03-01 16:16:26 -0800",
"2011-03-02 16:16:26 -0800",
"2011-03-03 16:16:26 -0800",
"2011-03-04 16:16:26 -0800",
"2011-03-05 16:16:26 -0800",
"2011-03-06 16:16:26 -0800",
"2011-03-07 16:16:26 -0800",
"2011-03-08 16:16:26 -0800",
"2011-03-09 16:16:26 -0800",
"2011-03-10 16:16:26 -0800",
"2011-03-11 16:16:26 -0800",
"2011-03-12 16:16:26 -0800",
"2011-03-13 16:16:26 -0700",
"2011-03-14 16:16:26 -0700",
"2011-03-15 16:16:26 -0700",
"2011-03-16 16:16:26 -0700",
"2011-03-17 16:16:26 -0700"
)
タイムゾーン オフセットが 3 月 13 日に から-0800
にどのように変化するかに注意してください-0700
。それがサマータイムです。:)