Created
October 5, 2020 07:03
-
-
Save ahmedbr/f5c1f3c1e45a36ed517e4c5b802c5135 to your computer and use it in GitHub Desktop.
Convert a Unix timestamp to time in JavaScript
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
function timeConverter(UNIX_timestamp){ | |
var a = new Date(UNIX_timestamp); | |
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; | |
var year = a.getFullYear(); | |
var month = months[a.getMonth()]; | |
var date = a.getDate(); | |
var hour = a.getHours(); | |
var min = a.getMinutes(); | |
var sec = a.getSeconds(); | |
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ; | |
return time; | |
} | |
console.log(timeConverter(1601881020038)); //5 Oct 2020 9:57:0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment