Skip to content

Instantly share code, notes, and snippets.

@pjlsergeant
Created September 24, 2010 11:27
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 pjlsergeant/595212 to your computer and use it in GitHub Desktop.
Save pjlsergeant/595212 to your computer and use it in GitHub Desktop.
function epochToAgo ( epoch ) {
var rightNowObj = new Date();
var rightNowEpoch = Math.floor(rightNowObj.getTime() / 1000);
var diff = rightNowEpoch - epoch;
var human;
if ( diff < 3600 ) {
human = Math.floor( diff / 60 ) + ' minutes ago';
} else if ( diff < 86400 ) {
human = Math.floor( diff / 3600 ) + ' hours ago';
} else {
var then = new Date();
then.setTime( epoch * 1000 );
human = then.toDateString().substr( 4, 6 );
}
return human;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment