dis = 3; //前后的天数
NSDate*nowDate = [NSDate date];
NSDate* theDate;
if(dis!=0)
{
NSTimeInterval oneDay = 24*60*60*1; //1天的长度
theDate = [nowDate initWithTimeIntervalSinceNow: +oneDay*dis ];
//or
theDate = [nowDate initWithTimeIntervalSinceNow: -oneDay*dis ];
}
else
{
theDate = nowDate;
}
//////////////////////////////////////////////////////////////
关键就是这句了:theDate = [nowDate initWithTimeIntervalSinceNow:+oneDay*dis ];