سؤال

I want to find the future date after adding a number of days to another date.

So if I have this:

 NSDateComponents *pastDate = [[NSDateComponents alloc] init];
        [pastDate setMonth:12];
        [pastDate setDay:23];
        [pastDate setYear:2011];

and want to add 90 days to find the future date. What method should I be looking at? I got creating another variable. I'm interested in what method. Thanks.

هل كانت مفيدة؟

المحلول

You might start with an NSDate, set it up by calling:

NSDate* pastDate = [NSDate dateWithTimeIntervalSinceReferenceDate:kStartDate];
NSDate* newDate = [pastDate dateByAddingTimeInterval:kNumSecondsIn90Days];

and converting to an NSDateComponent as described here. (Note that you'll have to define kStartDate as the number of seconds since January 1st, 2001 to 12/23/2011. And you'll have to define kNumSecondsIn90Days.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top