开发者

NSDate increment

i'm trying to increment nsdate by 1 month, however when it reaches the end of the year, the year does not update (starts again from the first mo开发者_开发百科nth)? How could this be fixed?

this is what code i used

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];


That's what the NSWrapCalendarComponents option does. Pass 0 instead to get the behavior you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜