-
-
Save wafe/ca2995cd199f3372e1c7034f19fbcf5c to your computer and use it in GitHub Desktop.
Convert seconds to a human readable representation
This file contains 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
export function convertTime(seconds) { | |
var seconds = parseInt(seconds, 10) | |
var hours = Math.floor(seconds / 3600) | |
var minutes = Math.floor((seconds - (hours * 3600)) / 60) | |
var seconds = seconds - (hours * 3600) - (minutes * 60) | |
if ( !!hours ) { | |
if ( !!minutes ) { | |
return `${hours}h ${minutes}m ${seconds}s` | |
} else { | |
return `${hours}h ${seconds}s` | |
} | |
} | |
if ( !!minutes ) { | |
return `${minutes}m ${seconds}s` | |
} | |
return `${seconds}s` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment