Last active
October 3, 2019 13:37
-
-
Save wiedymi/dc0478cbfa79db50d4cb570423640d5d to your computer and use it in GitHub Desktop.
miliseconds to hours with minutes
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
const toHours = time => { | |
const hours = new Date(time).getUTCHours() | |
const minutes = time / 60 / 1000 | |
let showMinutes | |
if (minutes.toFixed(0) === '60') { | |
showMinutes = '00' | |
} else { | |
if (minutes.toFixed(0).length === 1) { | |
showMinutes = '0' + minutes.toFixed(0) | |
} else { | |
showMinutes = minutes.toFixed(0) | |
} | |
} | |
return `${hours}.${showMinutes}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment