Skip to content

Instantly share code, notes, and snippets.

@wiedymi
Last active October 3, 2019 13:37
Show Gist options
  • Save wiedymi/dc0478cbfa79db50d4cb570423640d5d to your computer and use it in GitHub Desktop.
Save wiedymi/dc0478cbfa79db50d4cb570423640d5d to your computer and use it in GitHub Desktop.
miliseconds to hours with minutes
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