下一个月的,

NSDateFormatter *format=[[[NSDateFormatter alloc] init]autorelease];
[format setDateFormat:@"YYYY-MM-dd"];
NSDate *fromdate=[format dateFromString:date];


NSCalendar *calendar = [[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
//NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *componentsToAdd = [[NSDateComponents alloc] init];
// 1 上一个月
if (nextOrPre == 1)
{
[componentsToAdd setMonth:-1];
}
else
{
[componentsToAdd setMonth:1];
}

NSDate *dateAfterMonth = [calendar dateByAddingComponents:componentsToAdd toDate:fromdate options:0];
[componentsToAdd release];
[date setString:[format stringFromDate:dateAfterMonth]];
return date ;

posted @ 2013-05-13 14:55  路在脚下,  阅读(133)  评论(0编辑  收藏  举报