Convert 2010-04-16 16:30:00 to “Tomorrow Afternoon”

后端 未结 4 1866
南旧
南旧 2020-12-19 22:08

Convert 2010-04-16 16:30:00 to \"Tomorrow Afternoon\" or convert another date to \"this afternoon\", \"next year\", \"next week wednesday\". You get the picture. Anyone know

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 22:49

                       function gett($sam){
                       $times = time() - $sam;
                        if ($times == 60){
                        $times = "a minute ago";
                        }
            if (($times != 1) && ($times < 60) && ($times != 0)){
            $times = "$times seconds ago";
            }
            if ($times == 0){
            $times = "less than a second ago";
            }
            if ($times == 1){
            $times = "a second ago";
            }
    
            if ($times > 60 && $times < 3600){
            $times = ceil($times/60)." minutes ago";
            }
    
            if($times == 3600){
            $times = "an hour ago";
            }
            if($times > 3600 && $times < 86400){
            $times = ceil($times/3600)." hours ago";
            }
            if($times == 86400){
            $times = "a day ago";
            }
            if($times > 86400){
            $times = ceil($times/86400)." days ago";
            }
            return $times; }
    

    Usage: $updated = gett($timestamp); where $timestamp is pretty self-explanatory..

提交回复
热议问题