0

目前我正在使用 timeago 插件来显示时间。它已成功实施。但是有个小问题。当页面第一次加载时,它可以正常工作,几秒钟后它会显示any moment now在所有使用它的地方。这是插件的问题还是我以错误的方式实现。下面是我的实现代码。如果它的插件问题,请建议我其他时间之前完美运行的插件,并在不刷新页面的情况下更新它的时间。

jQuery

 $(window).load(function(){

 //timeago
   jQuery("abbr.timeago").timeago();
   jQuery.timeago.settings.allowFuture = true;
 //jQuery.timeago.settings.strings.inPast = "time has elapsed";
   jQuery.timeago.settings.allowPast = false;
 //timeago

});

HTML

 <abbr class="timeago" title="<?php echo $noti->date_time; ?>"></abbr>
  //$noti->date_time is from database. eg: 2014-11-15 22:46:38
4

2 回答 2

0

jQuery timeago 接受时间为 ISO8601 格式。

尝试这个:

对于 php 5.4+

echo (new DateTime($noti->date_time))->format(DateTime::ISO8601);

对于 < php 5.4

$date = new DateTime($ntoi->date_time);
echo $date->format(DateTime::ISO8601);
于 2014-11-16T03:52:50.210 回答
0
$(window).load(function() {
   jQuery("abbr.timeago").timeago();
   jQuery.timeago.settings.allowFuture = true;
   jQuery.timeago.settings.allowPast = true;
});
于 2014-11-16T04:36:24.017 回答