我可以通过“刚才”作为jquery timeago的时间来传递?
题
我正在使用jquery timeago让我的日期漂亮(例如“1天前”)。是否有“刚才”的关键字,或者我必须将JavaScript计算的时间传递给PHP?
<abbr class='timeago' title='What do I put here?'>Just Now</abbr>
. 解决方案
使用jquery插入时间戳。
var justnow = ISODateString(new Date());
$('abbr[title="just now"]').each(function() {
$(this).attr('title', justnow);
});
.
其中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';
}
.
不隶属于 StackOverflow