NSDate Gets Value 30th Day After Today

I need to set the NSDate to the 30th day after today. I am looking for a quick way to do this.

Tanks!

+3
source share
2 answers

According to Apple docs for NSDate there is a class method:

+ (id)dateWithTimeIntervalSinceNow:(NSTimeInterval)seconds

60 seconds / minutes * 60 minutes / hour * 24 hours / day * 30 days should provide you with the required number of seconds.

So try:

NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * 30];
+11
source

You can do it as follows:

NSDate *now = [NSDate date];

   // now a NSDate object for now + 30 days
   NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];


    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
    [offsetComponents setDay:30];
    NSDate *endDate = [gregorian dateByAddingComponents:offsetComponents toDate:now options:0];
    [offsetComponents release];

    [gregorian release];
+8
source

All Articles