# Answers for "how to convert seconds in hours minutes and seconds js"

2

how to convert seconds into days hours seconds js

``````function secondsToDhms(seconds) {
seconds = Number(seconds);
var d = Math.floor(seconds / (3600*24));
var h = Math.floor(seconds % (3600*24) / 3600);
var m = Math.floor(seconds % 3600 / 60);
var s = Math.floor(seconds % 60);

var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return dDisplay + hDisplay + mDisplay + sDisplay;
}``````
Posted by: Guest on December-15-2020
3

convert seconds to hours minutes seconds javascript

``````function secondsToHms(d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);

var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return hDisplay + mDisplay + sDisplay;
}``````
Posted by: Guest on November-18-2020
1

javascript hours minutes seconds

``````var myDate = new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "\$1");
console.log(myDate)
//using regex``````
Posted by: Guest on May-09-2021
1

convert seconds to minutes javascript

``````// just added 2 formats in Glorious Guanaco code
function secondsToHms(value) {
const sec = parseInt(value, 10);
let hours = Math.floor(sec / 3600);
let minutes = Math.floor((sec - hours * 3600) / 60);
let seconds = sec - hours * 3600 - minutes * 60;
if (hours < 10) {      hours = '0' + hours;    }
if (minutes < 10) {      minutes = '0' + minutes;    }
if (seconds < 10) {      seconds = '0' + seconds;    }
if (hours == 0) {
return +minutes + ':' + seconds; // Return in MM:SS format
} else {
return hours + ':' + minutes + ':' + seconds; // Return in HH:MM:SS format
}
}``````
Posted by: Guest on April-27-2021
0

how to convert seconds in hours minutes and seconds js

``````function convertSeconds(seconds) {
var convert = function(x) { return (x < 10) ? "0"+x : x; }
return convert(parseInt(seconds / (60*60))) + ":" +
convert(parseInt(seconds / 60 % 60)) + ":" +
convert(seconds % 60)
}``````
Posted by: Guest on October-12-2021