Posso passare a "solo adesso" come un momento per il timeago jQuery?
Domanda
Sto usando JQuery Timeago per rendere belle le date (ad esempio "1 giorno fa").C'è una parola chiave per "solo adesso" o devo passare nel tempo calcolato JavaScript a PHP?
<abbr class='timeago' title='What do I put here?'>Just Now</abbr>
. Soluzione
Usa jquery per inserire il timestamp per te.
var justnow = ISODateString(new Date());
$('abbr[title="just now"]').each(function() {
$(this).attr('title', justnow);
});
.
Dove IsodaTeString è:
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';
}
.
Esempio: http://jsfiddle.net/jtbowden/rzxzl/
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow