Created
September 24, 2010 11:27
-
-
Save pjlsergeant/595212 to your computer and use it in GitHub Desktop.
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 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