日付を増やして毎月フォーマットされた出力を取得しようとしています...正常に機能しますが、2010年12月から2011年1月までのステップは機能しません。これを見てください:
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *lastDate = [[NSDate alloc] init];
for (int i = 0; i < 12; i++) {
NSDateComponents *offsetComponents = [[[NSDateComponents alloc] init] autorelease];
[offsetComponents setMonth: 1];
lastDate = [[gregorian dateByAddingComponents:offsetComponents toDate: lastDate options:0] retain];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:@"MMMM YYYY"];
NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
[dateFormatter setLocale:locale];
NSLog(@"%d: Fromatted Date: %@ from : %@", i, [dateFormatter stringFromDate:lastDate], lastDate);
}
デバッグ出力:[セッションは2010-07-01 11:05:18+0200に開始されました。]0:開始日:2010年8月から:2010-08-01 11:05:19 +0200
1:Fromatted Date:2010年9月from:2010-09-01 11:05:19 +0200
2:Fromatted Date:2010年10月from:2010-10-01 11:05:19 +0200
3:Fromatted Date:2010年11月from:2010-11-01 11:05:19 +0100 4:Fromatted Date:2010年12月from:2010-12-01 11:05:19 +0100
5:Fromatted Date:2010年1月from:2011-01-01 11:05:19 +0100 <---なぜ2010年なのか?!
6:Fromatted Date:2011年2月from:2011-02-01 11:05:19 +0100
7:Fromatted Date:2011年3月from:2011-03-01 11:05:19 +0100
8:Fromatted Date:2011年4月from:2011-04-01 11:05:19 +0200
9:Fromatted Date:2011年5月from:2011-05-01 11:05:19 +0200
10:Fromatted Date:2011年6月from:2011-06-01 11:05:19 +0200
11:Fromatted Date:2011年7月from:2011-07-01 11:05:19 +0200