【问题标题】:momentjs format duration to [hh:mm:ss] with hh larger than 24hours时刻 js 格式持续时间为 [hh:mm:ss] 且 hh 大于 24 小时
【发布时间】:2017-09-12 16:06:36
【问题描述】:

如何使用 momentjs 以秒为单位格式化数字

moment(172800).format('hh[h] mm[min]')

给一些喜欢的人

'48h 00min'

本质上,我想计算 hh:mm:ss 中的计时器传递时间超过 24 小时。

【问题讨论】:

标签: momentjs


【解决方案1】:

你可以使用moment-duration-format插件。

您可以根据您的秒数创建一个duration,然后使用moment-duration-format 中的format 方法根据您的需要打印持续时间。

这里是一个例子:

// Create moment duration
var dur = moment.duration(172800, 's');
// Format duration according your needs
console.log( dur.format('hh[h] mm[min]') );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-duration-format/1.3.0/moment-duration-format.min.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-13
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    相关资源
    最近更新 更多