2017-09-12 93 views
0

如何使用momentjs格式化以秒爲數量等momentjs格式的持續時間爲[HH:MM:SS] hh的比24小時

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

一些像

'48h 00min' 
原發性

較大我想計數計時器通過hh:mm:ss的小時數超過24。

+0

對於這樣的事情,你應該使用['moment.duration()'](https://momentjs.com/docs/ #/持續時間/)。您正在使用持續時間,而不是特定的時間。 – Phylogenesis

+0

[使用moment.js可能的重複如何給一個持續時間的特定格式](https://stackoverflow.com/questions/45171723/using-moment-js-how-do-i-give-a-specific -format換一個持續時間) –

回答

0

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

您可以在幾秒鐘內創建一個duration,然後根據您的需要使用format方法moment-duration-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>

相關問題