dis = 3; //前后的天數(shù)
NSDate*nowDate = [NSDate date];
NSDate* theDate;
if(dis!=0)
{
NSTimeInterval oneDay = 24*60*60*1; //1天的長(zhǎng)度
theDate = [nowDate initWithTimeIntervalSinceNow: +oneDay*dis ];
//or
theDate = [nowDate initWithTimeIntervalSinceNow: -oneDay*dis ];
}
else
{
theDate = nowDate;
}
//////////////////////////////////////////////////////////////
關(guān)鍵就是這句了:theDate = [nowDate initWithTimeIntervalSinceNow:+oneDay*dis ];