Skip to content

Instantly share code, notes, and snippets.

@kn9ts
Created April 29, 2019 11:32
Show Gist options
  • Save kn9ts/19093b49afeaa1cea905854964ccf701 to your computer and use it in GitHub Desktop.
Save kn9ts/19093b49afeaa1cea905854964ccf701 to your computer and use it in GitHub Desktop.
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