0

I've seen plenty of conversions of the ISO 8601 timestamp in other languages but not come across one for Swift.

I'm looking to convert the typical response from the Youtube API:

let timestamp = "PT3M53S"

To a total number of seconds....

seconds: Int = 233

Any clues on how to do this, I am torn whether to split the expression up, looking for the number between "M" and "S" to equate to seconds.

Please also consider the expression could include Hours e.g.

let timestamp = "PT1H3M53S"
  • 1
    Possible duplicate of [How to Convert duration form youtube api in swift?](https://stackoverflow.com/questions/37048139/how-to-convert-duration-form-youtube-api-in-swift) – Jad Ghadry Sep 17 '18 at 07:18
  • Also some Swift code here: https://stackoverflow.com/q/1146416 – Martin R Sep 17 '18 at 07:20

0 Answers0