如何将毫秒转换为人类可读的形式? [英] How to convert milliseconds into human readable form?

查看:131
本文介绍了如何将毫秒转换为人类可读的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将任意数量的毫秒数转换成天数,小时,分钟秒。

I need to convert an arbitrary amount of milliseconds into Days, Hours, Minutes Second.

例如:10天,5小时,13分钟,1秒。

For example: 10 Days, 5 hours, 13 minutes, 1 second.

推荐答案

嗯,因为没有人加紧,我会写简单的代码来做到这一点:

Well, since nobody else has stepped up, I'll write the easy code to do this:

x = ms / 1000
seconds = x % 60
x /= 60
minutes = x % 60
x /= 60
hours = x % 24
x /= 24
days = x

我很高兴你停了几天,没有要求几个月。 :)

I'm just glad you stopped at days and didn't ask for months. :)

请注意,在上文中,假设 / 表示截断整数除法。如果您以 / 表示浮点除法的语言使用此代码,则需要根据需要手动截断该部门的结果。

Note that in the above, it is assumed that / represents truncating integer division. If you use this code in a language where / represents floating point division, you will need to manually truncate the results of the division as needed.

这篇关于如何将毫秒转换为人类可读的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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