Created
May 16, 2012 16:39
-
-
Save timsavery/2712015 to your computer and use it in GitHub Desktop.
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
function getTimeSince(start, end) { | |
var msSince = (end - start); | |
var msInDay = 24*60*60*1000 | |
, msInHour = 60*60*1000 | |
, msInMinute = 60*1000 | |
, msInSecond = 1000; | |
if (msSince > msInDay) { // greater than one day | |
return parseInt(msSince / msInDay).toString() + 'd Ago'; | |
} else if (msSince > msInHour) { // greater than one hour | |
return parseInt(msSince / msInHour).toString() + 'h Ago'; | |
} else if (msSince > msInMinute) { // greater than one minute | |
return parseInt(msSince / msInMinute).toString() + 'm Ago'; | |
} else { // seconds ago | |
var sSince = parseInt(msSince / msInSecond); | |
if (sSince > 0) { | |
return sSince.toString() + 's Ago'; | |
} else { | |
return "Just Now"; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment