如何将NSTimeInterval(秒)转换为分钟 [英] How to convert an NSTimeInterval (seconds) into minutes

查看:849
本文介绍了如何将NSTimeInterval(秒)转换为分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从某个事件中获得了一定数量的秒数。它存储在NSTimeInterval数据类型中。

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 minutes and seconds.

例如我有:326.4秒,我想将其转换为以下字符串:
5:26。

For example I have: "326.4" seconds and I want to convert it into the following string: "5:26".

实现目标的最佳方法是什么这个目标?

What is the best way to achieve this goal?

谢谢。

推荐答案

伪代码:

minutes = floor(326.4/60)
seconds = round(326.4 - minutes * 60)

这篇关于如何将NSTimeInterval(秒)转换为分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆