How to add one month to an NSDate?

前端 未结 9 2155
自闭症患者
自闭症患者 2020-12-23 11:01

How To Add Month To NSDate Object?

NSDate *someDate = [NSDate Date] + 30Days.....;
9条回答
  •  醉话见心
    2020-12-23 11:40

    You need to use NSDateComponents:

    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    [dateComponents setMonth:1];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *newDate = [calendar dateByAddingComponents:dateComponents toDate:originalDate options:0];
    [dateComponents release]; // If ARC is not used, release the date components
    

提交回复
热议问题