Last active
May 6, 2019 10:30
-
-
Save XianYeeXing/9498d73fc4408791fb81f2b19e83eabe to your computer and use it in GitHub Desktop.
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 convertTimestampToDateStr = timestamp => { | |
let d = new Date(timestamp), | |
yyyy = d.getFullYear(), | |
mm = ('0' + (d.getMonth() + 1)).slice(-2), | |
dd = ('0' + d.getDate()).slice(-2), | |
hh = d.getHours(), | |
h = hh, | |
min = ('0' + d.getMinutes()).slice(-2), | |
ampm = 'AM'; | |
if (hh > 12) { | |
h = hh - 12; | |
ampm = 'PM'; | |
} else if (hh === 12) { | |
h = 12; | |
ampm = 'PM'; | |
} else if (hh == 0) { | |
h = 12; | |
} | |
//// EX: 2019-05-06 22:17 PM | |
return yyyy + '-' + mm + '-' + dd + ' ' + h + ':' + min + ' ' + ampm; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment