convert time stamp to time ago in php?

前端 未结 2 1664
心在旅途
心在旅途 2021-01-16 21:14

I know this question has been asked several times and I found so many tutorials, blog posts about converting timestamp to ago time in php..

I have tried countless c

2条回答
  •  耶瑟儿~
    2021-01-16 21:14

    Check this function intval() - http://php.net/manual/en/function.intval.php The following code should help you out

    $seconds_ago = (time() - strtotime('2014-01-06 15:25:08'));
    
    if ($seconds_ago >= 31536000) {
        echo "Seen " . intval($seconds_ago / 31536000) . " years ago";
    } elseif ($seconds_ago >= 2419200) {
        echo "Seen " . intval($seconds_ago / 2419200) . " months ago";
    } elseif ($seconds_ago >= 86400) {
        echo "Seen " . intval($seconds_ago / 86400) . " days ago";
    } elseif ($seconds_ago >= 3600) {
        echo "Seen " . intval($seconds_ago / 3600) . " hours ago";
    } elseif ($seconds_ago >= 60) {
        echo "Seen " . intval($seconds_ago / 60) . " minutes ago";
    } else {
        echo "Seen less than a minute ago";
    }
    

提交回复
热议问题