PHP Time Since Function? [duplicate]
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');
精彩评论