Compiled JavaScript Code has been changed:
var X = function () {
var Z = navigator.userAgent;
return {
ie: Z.match(/MSIE\s([^;]*)/)
}
}();
var I = function (f) {
var h = new Date();
var d = new Date(f);
if (X.ie) {
d = Date.parse(f.replace(/( \+)/, " UTC$1"))
}
var g = h - d;
var a = 1000,
b = a * 60,
c = b * 60,
e = c * 24,
Z = e * 7;
if (isNaN(g) || g < 0) {
return ""
}
if (g < a * 7) {
return "right now"
}
if (g < b) {
return Math.floor(g / a) + " seconds ago"
}
if (g < b * 2) {
return "about 1 minute ago"
}
if (g < c) {
return Math.floor(g / b) + " minutes ago"
}
if (g < c * 2) {
return "about 1 hour ago"
}
if (g < e) {
return Math.floor(g / c) + " hours ago"
}
if (g > e && g < e * 2) {
return "yesterday"
}
if (g < e * 365) {
return Math.floor(g / e) + " days ago"
} else {
return "over a year ago"
}
};
12 comments
Thanks a bunch for this!
Thank you very much
function ago($a) { $b = strtotime("now"); $c = strtotime($a); $d = $b - $c; $minute = 60; $hour = $minute * 60; $day = $hour * 24; $week = $day * 7; if(is_numeric($d) && $d > 0) { if($d < 3) return "right now"; if($d < $minute) return floor($d) . " seconds ago"; if($d < $minute * 2) return "about 1 minute ago"; if($d < $hour) return floor($d / $minute) . " minutes ago"; if($d < $hour * 2) return "about 1 hour ago"; if($d < $day) return floor($d / $hour) . " hours ago"; if($d > $day && $d < $day * 2) return "yesterday"; if($d < $day * 365) return floor($d / $day) . " days ago"; return "over a year ago"; } }
Sorry Im not sure exactly how to use this?
to use:
created_at = "Wed, 08 Apr 2009 19:22:10 +0000";
alert(H(created_at));
thank u sir
Thank you!
Gracias!
var X = function () { var Z = navigator.userAgent; return { ie: Z.match(/MSIE\s([^;]*)/) } }(); var I = function (f) { var h = new Date(); var d = new Date(f); if (X.ie) { d = Date.parse(f.replace(/( \+)/, " UTC$1")) } var g = h - d; var a = 1000, b = a * 60, c = b * 60, e = c * 24, Z = e * 7; if (isNaN(g) || g < 0) { return "" } if (g < a * 7) { return "right now" } if (g < b) { return Math.floor(g / a) + " seconds ago" } if (g < b * 2) { return "about 1 minute ago" } if (g < c) { return Math.floor(g / b) + " minutes ago" } if (g < c * 2) { return "about 1 hour ago" } if (g < e) { return Math.floor(g / c) + " hours ago" } if (g > e && g < e * 2) { return "yesterday" } if (g < e * 365) { return Math.floor(g / e) + " days ago" } else { return "over a year ago" } };
Last work well in explorer thanks!!!
Thank you!!
for anyone still looking for a JavaScript implementation, use can now use Twitter's twitter-cldr-js.
see the TwitterCldr.TimespanFormatter / Relative Dates and Times.
https://github.com/twitter/twitter-cldr-js
Leave a Reply