Created
April 29, 2019 11:32
-
-
Save kn9ts/19093b49afeaa1cea905854964ccf701 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
convertToReadableDate(unixTimestamp) { | |
// Months array | |
const monthsArray = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; | |
// Convert timestamp to milliseconds | |
const date = new Date(unixTimestamp * 1000); | |
const year = date.getFullYear(); | |
const month = monthsArray[date.getMonth()]; | |
const day = date.getDate(); | |
const hours = date.getHours(); | |
const minutes = `0${date.getMinutes()}`; | |
const seconds = `0${date.getSeconds()}`; | |
// Display date time in MM-dd-yyyy h:m:s format | |
const convdataTime = `${month}-${day}-${year} ${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}`; | |
return convdataTime; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment