javascript date to hours minutes seconds code example
Example 1: 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;
}
Example 2: new Date() get speicifc hours min sec
new Date().getDate()
new Date().getDay()
new Date().getFullYear()
new Date().getHours()
new Date().getMilliseconds()
new Date().getMinutes()
new Date().getMonth()
new Date().getSeconds()
new Date().getTime()