Created
September 23, 2017 09:21
-
-
Save g1eb/62d9a48164fe7336fdf4845e22ae3d2c 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