Created
August 26, 2020 22:57
-
-
Save sistematico/e958b719c03b27f7efbf28026c750303 to your computer and use it in GitHub Desktop.
Convert Unix Timestamp to Date
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
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