Google-code-prettify

2013/12/16

Objective-Cで現在から1週間後を取得する

#import <Foundation/Foundation.h>

int main(int argc, char **argv)
{
        @autoreleasepool{
                NSDate *now = [[NSDate alloc] init];
                NSCalendar * cal = [NSCalendar currentCalendar];
                NSDateComponents *compo = [[NSDateComponents alloc] init];

                NSLog(@"%@", now);

                [compo setWeek:1];
                NSLog(@"%@", [cal dateByAddingComponents:compo toDate:now options:0]);
        }

        return 0;
}

0 件のコメント: