我知道如何在iOS中获取日期。我需要查找上周的日期。因此,例如,如果今天是05/27/2011,我需要能够获得05/20/2011
由于
答案 0 :(得分:6)
这很粗糙但可行:
NSDate *prevWeekDate = [currentDate dateByAddingTimeInterval:(-60 * 60 * 24 * 7)];
的详细信息
答案 1 :(得分:5)
怎么样:
NSCalendar * calendar = [NSCalendar currentCalendar]; NSDate * date = [NSDate date]; NSDateComponents *components = [[NSDateComponents alloc] init]; [components setWeek:-1]; NSDate * lastweek = [calendar dateByAddingComponents:components toDate:date options:0]; NSLog(@"%@", lastweek); [components release];