将Month Year函数转换为Time Ago PHP

时间:2012-11-01 20:18:47

标签: php datetime

  

可能重复:
  PHP How to find the time elapsed since a date time?

我有以下产生MONTH YEAR。

<?php echo date('F Y', strtotime($video['Video']['posted_date'])); ?>

我想将此输出到“时间”前。即3小时前,6个月前,2年前。 任何帮助将非常感谢。 谢谢 安迪

3 个答案:

答案 0 :(得分:1)

$now            = new DateTime(date("Y-m-d H:i:s"));
$videoPosted    = new DateTime($video['Video']['posted_date']);
$interval       = $now->diff($videoPosted);

echo $interval->format('%h hours, %m month and %d days ago');

仅在PHP版本&gt;使用时使用5.3

答案 1 :(得分:0)

如果您使用的是php 5.3+,那么您正在寻找DateInterval::format()

答案 2 :(得分:-1)

这有助于您计算日期差异:How to calculate the difference between two dates using PHP?

之后,您可以使用strtotime()

转换结果
相关问题