相关疑难解决方法(0)

从毫秒到小时,分钟,秒和毫秒

我需要从毫秒到(小时,分钟,秒,毫秒)的元组表示相同的时间量.例如:

10799999ms = 2h 59m 59s 999ms

以下伪代码是我唯一可以提出的:

# The division operator below returns the result as a rounded down integer
function to_tuple(x):
    h = x / (60*60*1000)
    x = x - h*(60*60*1000)
    m = x / (60*1000)
    x = x - m*(60*1000)
    s = x / 1000
    x = x - s*1000
    return (h,m,s,x)
Run Code Online (Sandbox Code Playgroud)

我敢肯定必须能够做得更聪明/更优雅/更快/更紧凑.

algorithm date pseudocode

38
推荐指数
3
解决办法
10万
查看次数

标签 统计

algorithm ×1

date ×1

pseudocode ×1