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

前端 未结 30 1767
太阳男子
太阳男子 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:26

    s2t=function (t){
      return parseInt(t/86400)+'d '+(new Date(t%86400*1000)).toUTCString().replace(/.*(\d{2}):(\d{2}):(\d{2}).*/, "$1h $2m $3s");
    }
    
    s2t(123456);
    

    result:

    1d 10h 17m 36s
    

提交回复
热议问题