Created
June 4, 2010 19:12
Revisions
-
ashafa revised this gist
Jun 4, 2010 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ /* * * JavaScript Pretty Date * * Copyright (c) 2008 John Resig (jquery.com) @@ -36,5 +35,5 @@ /* USAGE: "<a class='time' title='" + new Date([YOUR DATE HERE]).toString("u") + "' href='#'></a>" NOTE: The method .toString("u") for the Date object is added by Date.JS (http://datejs.com). */ -
ashafa created this gist
Jun 4, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ /* * * JavaScript Pretty Date * * Copyright (c) 2008 John Resig (jquery.com) * * Licensed under the MIT license. * */ // Takes an ISO time and returns a string representing how // long ago the date represents. function prettyDate(time){ var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")), now = new Date(), diff = ((now.getTime() - ((date.getTime()) - (0 * 60000))) / 1000), day_diff = Math.floor(diff / 86400); return day_diff <= 0 && ( diff < 30 && "just now" || diff < 60 && "less than a minute ago" || diff < 120 && "a minute ago" || diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" || diff < 7200 && "about an hour ago" || diff < 86400 && "about " + Math.floor( diff / 3600 ) + " hours ago") || day_diff == 1 && "yesterday" || day_diff + " days ago"; }; jQuery.fn.prettyDate = function() { return this.each(function() { var date = prettyDate(this.title); if ( date ) jQuery(this).text( date ); }); }; $("a.time").prettyDate(); // Wrap this in a setInterval set at every 30000ms for live updates. /* USAGE: "<a class='time' title='" + new Date([YOUR DATE HERE]).toString("u") + "' href='#'></a>" NOTE: The method .toString("u") for the Date object is added my Date.JS (http://datejs.com). */