iOS Format String into minutes and seconds

前端 未结 7 1244
清酒与你
清酒与你 2020-12-10 12:56

I am receiving a string from the YouTube JSONC api, but the duration is coming as a full number i.e 2321 instead of 23:21 or 2 instead of 0:02. How would I go about fixing t

7条回答
  •  温柔的废话
    2020-12-10 13:43

    You can subString the 2321 and get the first string as 23 and the second as 21 and convert them to int. Also check for the length of the text:

    if (text.length < 4)
       //add zeros on the left of String until be of length 4
    

提交回复
热议问题