すべての NSDate を から から 30 日後に取得したいと考えています。ただし、正しく動作しません。
ここに私が使用しているコードがあります:
for (int i = 0; i < days; i++) {
NSDate *today = [self getToday];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
components.day = i;
NSDate *nextMonth = [gregorian dateByAddingComponents:components toDate:today options:0];
NSDateComponents *nextMonthComponents = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit fromDate:nextMonth];
NSDateComponents *todayDayComponents = [gregorian components:NSDayCalendarUnit fromDate:today];
nextMonthComponents.day = todayDayComponents.day+i;
NSDate *nextMonthDay = [gregorian dateFromComponents:nextMonthComponents];
DLog(@"nextMonthDay = %@",nextMonthDay);
[months addObject:nextMonthDay];
}
リストを取得しています:
nextMonthDay = 2013-01-03 22:00:00 +0000
nextMonthDay = 2013-01-04 22:00:00 +0000
nextMonthDay = 2013-01-05 22:00:00 +0000
nextMonthDay = 2013-01-06 22:00:00 +0000
nextMonthDay = 2013-01-07 22:00:00 +0000
nextMonthDay = 2013-01-08 22:00:00 +0000
nextMonthDay = 2013-01-09 22:00:00 +0000
nextMonthDay = 2013-01-10 22:00:00 +0000
nextMonthDay = 2013-01-11 22:00:00 +0000
nextMonthDay = 2013-01-12 22:00:00 +0000
nextMonthDay = 2013-01-13 22:00:00 +0000
nextMonthDay = 2013-01-14 22:00:00 +0000
nextMonthDay = 2013-01-15 22:00:00 +0000
nextMonthDay = 2013-01-16 22:00:00 +0000
nextMonthDay = 2013-01-17 22:00:00 +0000
nextMonthDay = 2013-01-18 22:00:00 +0000
nextMonthDay = 2013-01-19 22:00:00 +0000
nextMonthDay = 2013-01-20 22:00:00 +0000
nextMonthDay = 2013-01-21 22:00:00 +0000
nextMonthDay = 2013-01-22 22:00:00 +0000
nextMonthDay = 2013-01-23 22:00:00 +0000
nextMonthDay = 2013-01-24 22:00:00 +0000
nextMonthDay = 2013-01-25 22:00:00 +0000
nextMonthDay = 2013-01-26 22:00:00 +0000
nextMonthDay = 2013-01-27 22:00:00 +0000
nextMonthDay = 2013-01-28 22:00:00 +0000
nextMonthDay = 2013-01-29 22:00:00 +0000
nextMonthDay = 2013-01-30 22:00:00 +0000
nextMonthDay = 2013-03-03 22:00:00 +0000
nextMonthDay = 2013-03-04 22:00:00 +0000
リストの最後は次のとおりです。
nextMonthDay = 2013-01-29 22:00:00 +0000
nextMonthDay = 2013-01-30 22:00:00 +0000
nextMonthDay = 2013-03-03 22:00:00 +0000
nextMonthDay = 2013-03-04 22:00:00 +0000
したがって、これは正しくありません。代わりにあるはずです
2013-01-29 22:00:00 +0000
2013-01-30 22:00:00 +0000
2013-03-01 22:00:00 +0000
2013-03-02 22:00:00 +0000
多分誰かがこれについて私を助けることができますか?
ありがとうございました。