Can I pass in “just now” as a time for JQuery Timeago?
Question
I'm using JQuery timeago to make my dates pretty (eg. "1 day ago"). Is there a keyword for "just now" or do I have to pass in the javascript calculated time to PHP?
<abbr class='timeago' title='What do I put here?'>Just Now</abbr>
Solution
Use jQuery to insert the timestamp for you.
var justnow = ISODateString(new Date());
$('abbr[title="just now"]').each(function() {
$(this).attr('title', justnow);
});
Where ISODateString is:
function ISODateString(d) {
function pad(n) {
return n < 10 ? '0' + n : n
}
return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + 'Z';
}
Example: http://jsfiddle.net/jtbowden/RZXzL/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow