如何在目标c中将秒转换为分钟

时间:2016-07-25 12:50:36

标签: objective-c

我想知道如何根据通过网络服务获取的网址将秒数转换为分钟和天数

enter image description here

我必须使用这些秒来显示用户的上一个活动 -

enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我使用此方法获取音频或视频播放器的总小时,分钟和秒数,以显示其持续时间。方法就像,

 - (NSString *)timeFormatted:(int)totalSeconds
{

int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;

NSString *finalString;

if (hours > 0) {

    finalString = [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];

}

else{


    finalString = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];

}

return finalString;
}

你可以制作类似这样的方法。

提示:

你可以得到类似的日子,

 int days = totalSeconds / 86400;