date / time convert to time since php

后端 未结 5 576
你的背包
你的背包 2021-01-14 10:14

Hello in my database date / time are in this format

2010-06-01T18:20:25+0000

I\'d like to echo that out to time passed since that date / t

5条回答
  •  终归单人心
    2021-01-14 10:32

    I changed one line of the above code for the case in which it was posted less than one minute ago.

        function ax_getRoughTimeElapsedAsText($iTime0, $iTime1 = 0)
        {
        if ($iTime1 == 0) { $iTime1 = time(); }
        $iTimeElapsed = $iTime1 - $iTime0;
    
        if ($iTimeElapsed < (60)) {
            return "Less than a minute ago";
        } else if ($iTimeElapsed < (60*60)) {
            $iNum = intval($iTimeElapsed / 60); $sUnit = "minute";
        } else if ($iTimeElapsed < (24*60*60)) {
            $iNum = intval($iTimeElapsed / (60*60)); $sUnit = "hour";
        } else if ($iTimeElapsed < (30*24*60*60)) {
            $iNum = intval($iTimeElapsed / (24*60*60)); $sUnit = "day";
        } else if ($iTimeElapsed < (365*24*60*60)) {
            $iNum = intval($iTimeElapsed / (30*24*60*60)); $sUnit = "month";
        } else {
            $iNum = intval($iTimeElapsed / (365*24*60*60)); $sUnit = "year";
        }
    
        return $iNum . " " . $sUnit . (($iNum != 1) ? "s" : "") . " ago";
        }
    

提交回复
热议问题