jin*_*ini 2 iphone objective-c nsdate ios
我知道如何在iOS中获取日期.我需要查找上周的日期.例如,如果今天是05/27/2011,我需要能够获得05/20/2011
谢谢
这很粗糙但可行:
NSDate *prevWeekDate = [currentDate dateByAddingTimeInterval:(-60 * 60 * 24 * 7)];
Run Code Online (Sandbox Code Playgroud)
单击dateByAddingTimeInterval上的详细信息:
怎么样:
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];
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |