Created
August 13, 2017 21:38
-
-
Save 0xB10C/2ea433a5dd58c1142328e5c1237ff61d to your computer and use it in GitHub Desktop.
A function that converts an integer (seconds) to a DHHMMSS string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toDHHMMSS = function () { | |
var sec_num = parseInt(this, 10); | |
var days = Math.floor(sec_num / 86400) | |
var hours = Math.floor((sec_num - (days * 86400)) / 3600); | |
var minutes = Math.floor(((sec_num - (days * 86400)) - (hours * 3600)) / 60); | |
var seconds = sec_num - (days * 86400) - (hours * 3600) - (minutes * 60); | |
if (hours < 10) {hours = "0"+hours;} | |
if (minutes < 10) {minutes = "0"+minutes;} | |
if (seconds < 10) {seconds = "0"+seconds;} | |
return days + "d " + hours+'h '+minutes+'m '+seconds+"s"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment