开发者

PHP Time Since Function? [duplicate]

This question already has answers here: Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago... (32 answers) Closed 9 years ago.

I'm looking for a function that will take in a unix timestamp and output something like this:

4 years, 3 months, 12 days, 4 hours and 23 minutes ago.

Everything I have found has been pretty dates that just say so开发者_运维百科mething similar to "5 years ago" which I don't want.


You want DateInterval's format method:

$date = new \DateTime();
$date->setTimestamp($timestamp);
$interval = $date->diff(new \DateTime('now'));
echo $interval->format('%y years, %m months, %d days, %h hours and %i minutes ago');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜