【问题标题】:JS - Convert Milliseconds into Minutes, Seconds and Hundreths of a secondJS - 将毫秒转换为分、秒和百分之一秒
【发布时间】:2018-08-11 19:59:55
【问题描述】:

我正在测量非常精确的时间,必须将毫秒转换为分钟、秒和百分之一秒。像这样:MM:SS.hh 任何帮助表示赞赏!

【问题讨论】:

  • 查看moment.js。特别是格式方法。
  • 除数即可

标签: javascript typescript time milliseconds


【解决方案1】:

这是一种方法。

假设您需要转换的毫秒数 (ms) 是 123,215。

让我们从分钟数MM开始。

Number of milliseconds in a minute = 1 minute * 60 seconds * 1000 milliseconds
                                   = 60,000

123,215 / 60,000 = 2 (truncate after dividing)

因此,原始毫秒数内有整整两分钟。

MM = 2。

接下来,从原来的毫秒数中去掉相当于 MM 的毫秒数。

123,215 - (2 * 60,000) = 3,215

用 3215 来计算 SS 的秒数。

在此处重复类似的过程。

Number of milliseconds in a second = 1 second * 1000 milliseconds = 1,000

3,215 / 1,000 = 3 (truncate after dividing)

SS = 3。

从原来的毫秒数中去掉相当于SS的毫秒数。

3,215 - (3 * 1000) = 215

你现在剩下的就是你所说的百分之几。

更准确地说,这些是不适合整秒的千分之一。

所以你的转换结果是:

02:03:215

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2014-02-13
    • 2012-09-27
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多