JavaScript seconds to time string with format hh:mm:ss

前端 未结 30 1419
太阳男子
太阳男子 2020-11-22 07:19

I want to convert a duration of time, i.e., number of seconds to colon-separated time string (hh:mm:ss)

I found some useful answers here but they all talk about conv

30条回答
  •  一向
    一向 (楼主)
    2020-11-22 07:48

    You can use Momement.js with moment-duration-format plugin:

    var seconds = 3820;
    var duration = moment.duration(seconds, 'seconds');
    var formatted = duration.format("hh:mm:ss");
    console.log(formatted); // 01:03:40
    
    
    
    
    

    See also this Fiddle

提交回复
热议问题