iOS获取两周的时间

// 获取当前时间,日期

NSDate*currentDate = [NSDatedate];

NSDateFormatter*dateFormatter = [[NSDateFormatteralloc]init];

[dateFormattersetDateFormat:@"YYYY-MM-dd"];

NSString*dateString = [dateFormatterstringFromDate:currentDate];

NSLog(@"当前时间:%@",dateString);

// 最近两周

NSDate*weekdate = [currentDatedateByAddingTimeInterval:14*3600*24];//追加14天

NSDateFormatter*dateCurrent = [[NSDateFormatteralloc]init];

[dateCurrentsetDateFormat:@"YYYY-MM-dd"];

NSString*dateStr = [dateFormatterstringFromDate:weekdate];

NSLog(@"最近两周==%@",dateStr);

你可能感兴趣的:(iOS获取两周的时间)