时间前插件现在显示任何时刻

时间:2014-11-16 03:34:33

标签: jquery html timeago

目前我正在使用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

2 个答案:

答案 0 :(得分:0)

jQuery timeago接受ISO8601格式的时间。

试试这个:

for php 5.4 +

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

for&lt; php 5.4

$date = new DateTime($ntoi->date_time);
echo $date->format(DateTime::ISO8601);

答案 1 :(得分:0)

$(window).load(function() {
   jQuery("abbr.timeago").timeago();
   jQuery.timeago.settings.allowFuture = true;
   jQuery.timeago.settings.allowPast = true;
});
相关问题