Showing posts with label previous. Show all posts
Showing posts with label previous. Show all posts

Adding Days to an NSDate

iPhone SDK Tips & Tricks

NSDate *now = [NSDate date];
int daysToAdd = 50;
// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];
// create a calendar
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
NSLog(@"Clean: %@", newDate2);