Search code examples
iosiphoneobjective-cnsdate

How to add one month to an NSDate?


How To Add Month To NSDate Object?

NSDate *someDate = [NSDate Date] + 30Days.....;

Solution

  • You need to use NSDateComponents:

    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    [dateComponents setMonth:1];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *newDate = [calendar dateByAddingComponents:dateComponents toDate:originalDate options:0];
    [dateComponents release]; // If ARC is not used, release the date components