use*_*244 0 iphone xcode objective-c
是否有可能按月增加NSDATE?例如,nsdate = 12/10/01,增加一个月使其成为12/11/01.
您需要使用NSCalendar类进行日历计算:
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];
Run Code Online (Sandbox Code Playgroud)