jquery convert time to 1day 2 minutes 4 seconds

Solutions on MaxInterview for jquery convert time to 1day 2 minutes 4 seconds by the best coders in the world

showing results for - "jquery convert time to 1day 2 minutes 4 seconds"
Kenna
31 Apr 2019
1function secondsToDhms(seconds) {
2  seconds = Number(seconds);
3  var d = Math.floor(seconds / (3600*24));
4  var h = Math.floor(seconds % (3600*24) / 3600);
5  var m = Math.floor(seconds % 3600 / 60);
6  var s = Math.floor(seconds % 60);
7
8  var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
9  var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
10  var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
11  var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
12  return dDisplay + hDisplay + mDisplay + sDisplay;
13}