开发者

NSDate increment

开发者 https://www.devze.com 2023-02-22 05:17 出处:网络
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?

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

精彩评论

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