Here you can find the source of ago()
/**//ww w . ja v a 2 s . c o m * Provides a Twittereque "ago" time. */ Date.prototype.ago = function () { var now = new Date(); var seconds_ago = (now.getTime() - this.getTime()) / 1000; var time = Math.floor(seconds_ago / 86400); var s = (time == 1) ? "" : "s"; if (seconds_ago < 60) { return "less than a minute ago"; } else if (seconds_ago < 3600) { time = Math.round(seconds_ago / 60); s = (time == 1) ? "" : "s"; return time.toString() + " minute" + s + " ago"; } else if (seconds_ago < 86400) { time = Math.floor(seconds_ago / 3600); s = (time == 1) ? "" : "s"; if (time == 1) time = "an"; return "over " + time.toString() + " hour" + s + " ago"; } };
Number.prototype.ago = function() { var d = new Date(); return (d.getTime() - this); };
Number.prototype.ago = function () { var i = this.valueOf(); var t = new Date().getTime(); return new Date(t - i); };
Date.prototype.ago = function() { var diff = (((new Date()).getTime() - this.getTime()) / 1000) , day_diff = Math.floor(diff / 86400); return day_diff == 0 && ( diff < 60 && "just now" || diff < 120 && "1 minute ago" || diff < 3600 && Math.floor( diff/60 ) + " minutes ago" || diff < 7200 && "1 hour ago" || diff < 86400 && Math.floor( diff/3600 ) + " hours ago") || ...
Date.prototype.Ago = function () var msPerMinute = 60 * 1000; var msPerHour = msPerMinute * 60; var msPerDay = msPerHour * 24; var msPerMonth = msPerDay * 30; var msPerYear = msPerDay * 365; var elapsed = new Date() - this; if (elapsed < msPerMinute) ...