iOS Format String into minutes and seconds

前端 未结 7 1220
清酒与你
清酒与你 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:46

    Here is the great code I finds for this

    int duration = 1221;
    int minutes = floor(duration/60)
    int seconds = round(duration - (minutes * 60))
    NSString * timeStr = [NSString stringWithFormat:@"%i:%i",minutes,seconds];
    NSLog(@"Dilip timeStr : %@",timeStr);
    

    And the output will belike this

    Dilip timeStr : 20:21
    
    0 讨论(0)
提交回复
热议问题