【问题标题】:Jquery Timeago plugin to work with unix timestampJquery Timeago 插件与 unix 时间戳一起使用
【发布时间】:2023-03-30 04:46:01
【问题描述】:

我正在尝试使 timeago 插件使用以下时间戳

2017-03-16 18:37:20

然后我尝试将其转换为这个时间戳。但它仍然无法正常工作

1489685840

这里是代码

  <script src="jquery.timeago.js" type="text/javascript"></script>
<script src="jquery.min.js" type="text/javascript"></script>
  <script src="jquery.livequery.min" type="text/javascript"></script>

<script type="text/javascript">
jQuery(document).ready(function() {
  jQuery(".demo_class").timeago();
});
</script>

由于我试图在表格中执行此操作。这里是负责的代码

<td>
                    <?php 
  $datetime = $row['date'];
  $datetime = strtotime($datetime);
?>
You opened this page <span  class='demo_class' ><?php echo $datetime ; ?></span>
</td>

如果可能的话,你能帮我让代码自动更新吗?就像时间会自动改变而不刷新一样

Timeago 使用类似的东西

2008-07-17T09:24:17Z

【问题讨论】:

  • 你告诉我们 timeago 期望什么格式?我们不会为你阅读它的文档
  • 更新了问题。
  • 你可以用 php date() 或 mysql DATE_FORMAT() 格式化日期

标签: javascript php jquery


【解决方案1】:

jquery-timeago 的作者在这里。

As the docs referenceISO 8601 时间戳是一切都按预期在 timeago 之前工作所必需的:

<time class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</time>

在 PHP 中,你需要一个像这样的 sn-p 来输出 ISO 8601 格式:

$time->format(DateTime::ISO8601);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 2011-11-06
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 2019-09-02
    相关资源
    最近更新 更多