PHP 转换时间戳为”今天”等格式

/**
     * 转换时间戳为"今天"等格式
     * 调用方法  $this->wordTime($time)
     * $time--要转换的时间戳
     * 
     */
    public function wordTime($time)
    {
        $time = (int) substr($time, 0, 10);
        //今天
        $newTime  = date("Y-m-d");
        $new      = strtotime($newTime);
        $endTime  = date("Y-m-d", $time);
        $end      = strtotime($endTime);
        $int = $new - $end;
        $str = '';
        if ($int == 0) {
            $str = '今天 '.date('H:i', $time);
        } else {
            $str = date('m-d H:i', $time);
        }
        return $str;
    }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Back To Top

鄂ICP备17008157号-1