Basically, as the title says. I'm wondering how I could add 1 day to an NSDate
.
So if it were:
21st February 2011
It would become:
22nd February 2011
Or if it were:
31st December 2011
It would become:
1st January 2012.
Basically, as the title says. I'm wondering how I could add 1 day to an NSDate
.
So if it were:
21st February 2011
It would become:
22nd February 2011
Or if it were:
31st December 2011
It would become:
1st January 2012.
You can use NSDate's method
- (id)dateByAddingTimeInterval:(NSTimeInterval)seconds
whereseconds
would be60 * 60 * 24 = 86400
Use the below function and use days paramater to get the date daysAhead/daysBehind just pass parameter as positive for future date or negative for previous dates:
Swift 4, if all you really need is a 24 hour shift (60*60*24 seconds) and not "1 calendar day"
Future:
let dayAhead = Date(timeIntervalSinceNow: TimeInterval(86400.0))
Past:
let dayAgo = Date(timeIntervalSinceNow: TimeInterval(-86400.0))
Swift 4.0 (same as Swift 3.0 in this wonderful answer just making it clear for rookies like me)