Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add one month to an NSDate?

How To Add Month To NSDate Object?

NSDate *someDate = [NSDate Date] + 30Days.....; 
like image 236
or azran Avatar asked Nov 14 '11 09:11

or azran


People also ask

How do I increment a date in Swift?

To add more days to a current date object, you can use the Calendar and the DateComponents() Swift structs. let currentDate = Date() var dateComponent = DateComponents() dateComponent. day = 1 let futureDate = Calendar.

How can I get tomorrow date in Swift?

Component, value: Int) -> Date { let noon = Calendar. current. date(bySettingHour: 12, minute: 0, second: 0, of: self)! return Calendar.


1 Answers

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 
like image 194
TheEye Avatar answered Oct 09 '22 08:10

TheEye