I have dateformat string like this "2015-03-09".How do i get next 10 days date from current date?any help will be appreciated.thanks in advance
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
Here is a swift 4/5 version of the answer by @MidhunMP
You can use the dateByAddingTimeInterval() method for this.
EDIT:
As mentioned by @Martin R in the comments, it'll be better to use dateByAddingComponents() of NSCalendar class:
There is a function 'dateByAddingTimeInterval()' for an NSDate object. With this, you can create a NSDate from your date string. Then add 10 days = 10*24*60*60 to get next 10 days NSDate value
To avoid problem with Daylighttime saving (@MartinR):
For Swift 3:
Here's how to get a date 10 days from now, using built-in date modification method .dateByAddingUnit If all 10 days (dates) are required, can be looped by "value:10" part and added to array.
And for Swift3:
For a purely Swift 3 solution: