NSString *time = @"2016-11-08";
NSDateFormatter *fm = [[NSDateFormatter alloc] init];
fm.dateFormat = @"yyyy-MM-dd";
NSDate *date = [fm dateFromString:time];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:NSCalendarUnitYear |NSCalendarUnitMonth|NSCalendarUnitDay fromDate:date];
NSLog(@"\n%ld\n%ld\n%.02ld", (long)components.year, (long)components.month, (long)components.day);
运行结果
2016
11
08