Iphone NSDate增量

Iphone NSDate增量,iphone,objective-c,xcode,sdk,Iphone,Objective C,Xcode,Sdk,我试图将nsdate增加1个月,但是当它到达年底时,年份不会更新(从第一个月开始)?这怎么能解决呢 这就是我使用的代码 NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; NSDateComponents *comp = [[[NSDateComponents alloc] init] autorelease]; [comp setMo

我试图将nsdate增加1个月,但是当它到达年底时,年份不会更新(从第一个月开始)?这怎么能解决呢

这就是我使用的代码

NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comp = [[[NSDateComponents alloc] init] autorelease];
[comp setMonth: 1];
NSDate* newDate = [gregorian dateByAddingComponents:comp toDate:oldDate options:NSWrapCalendarComponents];

这就是
NSWrapCalendarComponents
选项的作用。而是传递
0
以获得所需的行为。

这就是
NSWrapCalendarComponents
选项的作用。而是传递
0
,以获得所需的行为