使用 Javascript 的 Twitter 式时间前格式(“2h”)

贝万布

Timeago.js在格式化相对于当前时间(“大约 2 小时前”)的时间戳方面做得很好。

是否有任何解决方案可以完成相同的事情,但缩写?IE "2h",就像 Twitter 使用的那样。

施伦格

您可以使用 Timeago.js 并使用缩写版本覆盖本地时间格式,例如

var locale = function(number, index, total_sec) {
  return [
    ['just now', 'right now'],
    ['%s s ago', 'in %s s'],
    ['1 m ago', 'in 1 m'],
    ['%s m ago', 'in %s m'],
    ['1 h ago', 'in 1 h'],
    ['%s h ago', 'in %s h'],
    ....
  ][index];
};

timeago.register('pt_ABBR', locale);
var timeagoInstance = timeago();

// then you can use it
timeagoInstance.format(1473245023718, 'pt_ABBR');

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章