Skip to content

Instantly share code, notes, and snippets.

@eddex
Created April 24, 2017 12:28
Show Gist options
  • Save eddex/9e8d646c7025d192e5ce661e17460579 to your computer and use it in GitHub Desktop.
Save eddex/9e8d646c7025d192e5ce661e17460579 to your computer and use it in GitHub Desktop.
convert epoch (unix) timestamp to a readable format (node.js)
/*
* Convert the epoch (unix) timestamp to a readable format.
*/
function formatDateTime(epochTimeStamp, callback) {
var d = new Date(epochTimeStamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = d.getFullYear();
var month = months[d.getMonth()];
var date = d.getDate();
var hour = d.getHours();
var min = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes();
var sec = (d.getSeconds() < 10 ? '0' : '') + d.getSeconds();
var time = date + '. ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
callback(time);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment