How to convert an NSTimeInterval (seconds) into minutes

前端 未结 12 960
轮回少年
轮回少年 2020-11-28 01:27

I\'ve got an amount of seconds that passed from a certain event. It\'s stored in a NSTimeInterval data type.

I want to convert it into

12条回答
  •  一整个雨季
    2020-11-28 01:58

    Brian Ramsay’s code, de-pseudofied:

    - (NSString*)formattedStringForDuration:(NSTimeInterval)duration
    {
        NSInteger minutes = floor(duration/60);
        NSInteger seconds = round(duration - minutes * 60);
        return [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
    }
    

提交回复
热议问题