Skip to content

Instantly share code, notes, and snippets.

@wiedymi
Created December 12, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wiedymi/daac548eeb9187c12d187f9964bb15aa to your computer and use it in GitHub Desktop.
Save wiedymi/daac548eeb9187c12d187f9964bb15aa to your computer and use it in GitHub Desktop.
export const convertTime = (time): string => {
const date = new Date(+`${time}000`)
let hours = date.getHours()
let minutes = date.getMinutes()
const ampm = hours >= 12 ? 'PM' : 'AM'
hours = hours % 12
hours = hours ? hours : 12
minutes = minutes < 10 ? '0' + minutes : minutes
const strTime = hours + ':' + minutes + ' ' + ampm
return strTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment