Skip to content

Instantly share code, notes, and snippets.

@sistematico
Created August 26, 2020 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sistematico/e958b719c03b27f7efbf28026c750303 to your computer and use it in GitHub Desktop.
Save sistematico/e958b719c03b27f7efbf28026c750303 to your computer and use it in GitHub Desktop.
Convert Unix Timestamp to Date
let unix_timestamp = 1549312452;
let date = new Date(unix_timestamp * 1000);
let hours = "0" + date.getHours();
let minutes = "0" + date.getMinutes();
let seconds = "0" + date.getSeconds();
let days = "0" + date.getDate();
let months = "0" + date.getMonth();
let years = date.getFullYear();
let formattedTime = days.substr(-2) + '/' + months.substr(-2) + '/' + years + ' ' + hours.substr(-2) + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
console.log(formattedTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment