繁体   English   中英

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

[英]Convert seconds into hh:mm:ss format using moment.js

我试图以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);
moment("1900-01-01 00:00:00").add(43000/1000, 'seconds').format("HH:mm:ss")

尝试这个?

时刻的持续时间在定义中没有毫秒数,你应该除以1000。

http://momentjs.com/docs/#/manipulating/add/

http://momentjs.com/docs/#/durations/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM