Created
April 24, 2017 12:28
-
-
Save eddex/9e8d646c7025d192e5ce661e17460579 to your computer and use it in GitHub Desktop.
convert epoch (unix) timestamp to a readable format (node.js)
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
/* | |
* 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