Last active
April 11, 2020 09:42
-
-
Save shanebo/3412560d72114491339bfdddb298c8af to your computer and use it in GitHub Desktop.
Simple seconds to hh:mm:ss functions
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
// this has a max of 24 hrs | |
const timeLeft = (secs) => | |
new Date(secs * 1000) | |
.toISOString() | |
.substr(11, 8) | |
.replace(/^([00:])*/g, '') || '0'; | |
// this could be extended to include days | |
const timeLeft = (time) => { | |
const hrs = Math.floor(time / 3600); | |
const mins = Math.floor((time % 3600) / 60); | |
const secs = Math.floor(time % 60); | |
return [hrs, mins, secs] | |
.map(n => n < 10 ? `0${n}` : n.toString()) | |
.join(':') | |
.replace(/^([00:])*/g, '') || '0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment