user648244
user648244

Reputation: 1278

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 month)? 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];

Upvotes: 0

Views: 828

Answers (1)

Chuck
Chuck

Reputation: 237080

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

Upvotes: 5

Related Questions