Created
September 9, 2020 06:11
-
-
Save desaijay315/94cd69a8729b67a4c2d41ef9d73778b3 to your computer and use it in GitHub Desktop.
Javascript unix timestamp to date time conversion
This file contains hidden or 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 = 1599629512236 | |
// Create a new JavaScript Date object based on the timestamp | |
// multiplied by 1000 so that the argument is in milliseconds, not seconds. | |
var date = new Date(unix_timestamp); | |
// Hours part from the timestamp | |
var hours = date.getHours(); | |
var day = date.getDate(); | |
// Minutes part from the timestamp | |
var minutes = "0" + date.getMinutes(); | |
// Seconds part from the timestamp | |
var seconds = "0" + date.getSeconds(); | |
// Will display time in 10:30:23 format | |
var formattedTime = day + ':' + hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment