最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Convert seconds into hh:mm:ss format using moment.js - Stack Overflow

programmeradmin0浏览0评论

I am trying to convert seconds in hh:mm:ss format . I have using below code to convert seconds into hours,min. but I don't want to do all this. Is it possible in moment.js to convert seconds into HH:MM:SS format. rather than doing it manually.

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);

I am trying to convert seconds in hh:mm:ss format . I have using below code to convert seconds into hours,min. but I don't want to do all this. Is it possible in moment.js to convert seconds into HH:MM:SS format. rather than doing it manually.

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);
Share Improve this question asked Sep 20, 2016 at 6:25 KalashirKalashir 1,1274 gold badges16 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7
moment("1900-01-01 00:00:00").add(43000/1000, 'seconds').format("HH:mm:ss")

try this?

moment's duration doesn't have millisec in their definition, you should divide it by 1000.

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

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

发布评论

评论列表(0)

  1. 暂无评论