iphone 日期计算

-(NSDate *)getPriousDateFromDate:(NSDate *)date withMonth:(int)month
{
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setMonth:month];
    NSCalendar *calender = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *mDate = [calender dateByAddingComponents:comps toDate:date options:0];
    [comps release];
    [calender release];
    return mDate;
}

NSDate *priousDate = [self getPriousDateFromDate:[NSDate date]    withMonth:-3];
 

你可能感兴趣的:(iPhone)