Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何获取当前日期的前7天日期?_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 如何获取当前日期的前7天日期?

Iphone 如何获取当前日期的前7天日期?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我在一个项目上工作,我需要在用户从日期选择器选择的特定日期前7天设置警报 我使用以下代码从用户处获取日期 NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateStyle:NSDateFormatterFullStyle]; NSString *dateStr = [NSString stringWithFormat:@"%@",[df stringFromDate:datePickerObj.date]]; [df re

我在一个项目上工作,我需要在用户从日期选择器选择的特定日期前7天设置警报

我使用以下代码从用户处获取日期

NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateStyle:NSDateFormatterFullStyle];
NSString *dateStr = [NSString stringWithFormat:@"%@",[df stringFromDate:datePickerObj.date]];
[df release];
有人能告诉我如何得到所选日期前7天的日期吗。
提前感谢

使用
dateByAddingComponents:toDate:options:
,如下所示:

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
components.day = -7;
NSDate *earlierDate = [calendar dateByAddingComponents:components
    toDate:datePickerObj.date options:0];

全部7天?或所选日期前7天?@ThomasW所选日期前7天