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.
精彩评论