如何获得当前和未来三天的月份详情ios

时间:2015-01-19 12:52:31

标签: ios iphone xcode

是否可以在iOS应用程序中获取当前和未来三天的月份详细信息。

1 个答案:

答案 0 :(得分:0)

    NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
    dayComponent.day = 1; // Here add your days

    NSCalendar *theCalendar = [NSCalendar currentCalendar];
    NSDate *nextDate = [theCalendar dateByAddingComponents:dayComponent toDate:[NSDate date] options:0];


    NSLog(@"nextDate: %@ ...", nextDate);

月信息:

    unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [calendar components:units fromDate: nextDate];
    // get your month
    NSInteger month = [components month];