Swift 4 Extension which converts ISO 8601 duration strings into a ‘DateComponents‘ object
PT12H = 12 hours
P3D = 3 days
P3DT12H = 3 days, 12 hours
P3Y6M4DT12H30M5S = 3 years, 6 months, 4 days, 12 hours, 30 minutes and 5 seconds
P10W = 70 days
For more information look here: https://en.wikipedia.org/wiki/ISO_8601#Durations
var durationString = "P3Y6M4DT12H30M5S"
var components = DateComponents.durationFrom8601String(durationString)
If you like my open source libraries, you can sponsor it!
This file is licensed under the MIT License.
Objective-C version from @kevinrandrup