使用moment.js将秒转换为hh:mm:ss格式

4

我正在尝试把秒数转换成hh:mm:ss格式。我已经使用以下代码将秒数转换为小时、分钟,但我不想这样做。在moment.js中是否可能将秒数转换为HH:MM:SS格式,而不是手动进行转换。

var x = 43000
var durationValue = moment.duration(x, 'milliseconds');
var hours = Math.floor(durationValue.asHours());
var mins = Math.floor(durationValue.asMinutes()) - hours * 60;
console.log("hours:" + hours + " mins:" + mins);
1个回答

7

请描述一下 moment("1900-01-01 00:00:00") 这个函数。我不明白为什么要提供这个参数。 - Kalashir
1
moment("1900-01-01 00:00:00") 只是一个虚假的日期,但我们想要一个有效的 moment 对象。moment("2016-09-20 00:00:00") 也应该可以工作。我们不关心日期部分。 - tsohr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接