Created
April 29, 2021 04:31
-
-
Save k8scat/2b43041bacdabc5aaa90acfbecd8d8e1 to your computer and use it in GitHub Desktop.
Format time from timestamp
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 const formatTime = (timestamp) => { | |
const date = new Date(timestamp); | |
const YY = date.getFullYear(); | |
const MM = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1; | |
const DD = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate(); | |
const hh = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(); | |
const mm = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(); | |
const ss = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(); | |
return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment