Convert seconds to days, hours, minutes and seconds

前端 未结 8 1436
陌清茗
陌清茗 2020-12-03 16:45

I have a Javascript timing event with an infinite loop with a stop button.

It will display numbers when start button is click.Now I want this numbers converted to so

8条回答
  •  情歌与酒
    2020-12-03 17:08

    Here is my solution, a simple function that will round to the nearest second!

    var returnElapsedTime = function(epoch) {
      //We are assuming that the epoch is in seconds
      var hours = epoch / 3600,
          minutes = (hours % 1) * 60,
          seconds = (minutes % 1) * 60;
      return Math.floor(hours) + " hours, " + Math.floor(minutes) + " minutes, " + Math.round(seconds) + " seconds";
    }

提交回复
热议问题