[英]How to get the date a week in the past from today?
我知道如何在 iOS 中獲取日期。 我需要找到上周的日期。 因此,例如,如果今天是 05/27/2011,我需要能夠獲得 05/20/2011
謝謝
這是粗略的,但會起作用:
NSDate *prevWeekDate = [currentDate dateByAddingTimeInterval:(-60 * 60 * 24 * 7)];
怎么樣:
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.