明天将在NSDateComponents中隔离一天

时间:2011-09-30 15:28:49

标签: iphone objective-c ios nsdatecomponents

我正在尝试根据当前日期检索明天日期。我得到了正确的字符串,但是如何隔离这一天呢?

NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:1];
NSDate *tommorrow = [cal dateByAddingComponents:comps toDate:[NSDate date]  options:0];
[comps release];

NSLog(@"%@", tommorrow);

返回一个字符串:2011-10-01 15:07:07 +0000

1 个答案:

答案 0 :(得分:1)

你可以像这样

NSDateComponents *dcs = [cal components:NSDayCalendarUnit fromDate:tomorrow];
int day = [dcs day];