私はこのような日付を作成しています:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY"];
NSInteger year = [[dateFormatter stringFromDate:[NSDate date]] intValue];
NSLog(@"NSInteger YEAR : %d\n", year);
//minutes, hours, day and month are initialized elsewhere...
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:year];
[comps setMonth:month];
[comps setDay:day];
[comps setHour:hours];
[comps setMinute:minutes];
NSDate *sampleDate = [gregorian dateFromComponents:comps];
NSLog(@"sampleDate YEAR : %d\n", [[dateFormatter stringFromDate:sampleDate] intValue]);
私の問題は、日付が 1 月 1 日または 1 月 2 日の場合、年が正しくないことです。ここでは 2010 年 (今日の年を取得した場合) のはずですが、実際には 2009 年です...理由がわかりません! そして、これはその2日間だけ起こっています...
なぜそのようになっているのか分かりますか?前もって感謝します。