如何使用 Moment.js 持续时间格式从持续时间中删除标点符号

How to remove punctuation from time duration with Moment.js duration format

我正在使用 moment duration format 来计算总持续时间,它工作正常,但是当持续时间为 4 位数字时,它会以小时为单位添加逗号(考虑货币格式)。

我有:

moment.duration(33869100, 'seconds').format('hh:mm:ss', {trim: false})

输出:9,408:05:00 ---> 注意时间有逗号我需要这种格式 9408:05:00 没有逗号没有钱格式。

我不确定 Moment 是否可以为您更改,但您可以,只需进行替换即可:

/* using regex, .replace(/,/g, '') replaces all commas in case you run into large numbers */
moment.duration(33869100, 'seconds').format('hh:mm:ss', {trim: false}).replace(/,/g, '')

Here's a fiddle showing it working

编辑:参考@George 的回答,Moment 可以为您完成

你可以简单地disable grouping这样

moment.duration(33869100, 'seconds').format('hh:mm:ss', {trim: false, useGrouping: false})