11
从当前日期减去7天
看来我无法从当前日期减去7天。这就是我的做法: NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *offsetComponents = [[NSDateComponents alloc] init]; [offsetComponents setDay:-7]; NSDate *sevenDaysAgo = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; SevenDaysAgo的值与当前日期相同。 请帮忙。 编辑:在我的代码中,我忘记了用正确的日期替换获取当前日期的变量。因此上面的代码是功能正常的。
117
objective-c
ios
nsdate