Created
December 12, 2019 12:04
-
-
Save wiedymi/daac548eeb9187c12d187f9964bb15aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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