PHP判断时间是今天,明天,后天...

借鉴判断时间在过去的范围

https://www.it610.com/article/1290972637215924224.htm

 

代码展示

function setTime($targetTime)
    {
        //今天最小时间
        $todayLasted = strtotime(date('Y-m-d 00:00:00'));
        $abortTime = strtotime($targetTime);
        $afterTimeTrue = $abortTime - time();
        $afterTime = $abortTime - $todayLasted;
        $afterDay = floor($afterTime / 86400);
        $result = $targetTime;
      

        if ($afterTimeTrue > 0 && $afterTimeTrue < 3600) {
            $result = (ceil($afterTimeTrue / 60)) . '分钟后';
        } elseif ($afterTimeTrue < 3600 * 12) {
            $result = (ceil($afterTimeTrue / 3600)) . '小时后';
        } elseif ($afterDay == 0) {
            $result = '今天 ';
        } elseif ($afterDay == 1) {
            $result = '明天 ';
        } elseif ($afterDay == 2) {
            $result = '后天 ';
        } elseif ($afterDay > 2 && $afterDay < 8) {
            $result = $afterDay . '天后';
        }
        return $result;

  

 

posted on 2020-12-02 09:33  金知道  阅读(752)  评论(0编辑  收藏  举报