Skip to content

Instantly share code, notes, and snippets.

@ahmedbr
Created October 5, 2020 07:03
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 ahmedbr/f5c1f3c1e45a36ed517e4c5b802c5135 to your computer and use it in GitHub Desktop.
Save ahmedbr/f5c1f3c1e45a36ed517e4c5b802c5135 to your computer and use it in GitHub Desktop.
Convert a Unix timestamp to time in JavaScript
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