php计算年龄,x岁,x月,x天

php计算年龄,x岁,x月,x天,第1张

php计算年龄

 //接收时间
    public function selOneTime(){
    	$data = request()->post('time');
        $time = time()-$data;
        return $this->ageSum($time);
    }
//计算年龄
    public function ageSum($time){
        $value = [
            "years" => '', "mou" => '零',"days" => '1',
        ];
        if ($time >= 31556926) {
            $value["years"] = floor($time/31556926). "岁";
            $time = ($time%31556926);
        }
        if ($time >=2626560){
            $value["mou"] = floor($time/2626560)."个月";
            $time = ($time%2626560);
        }
        if ($time >= 86400) {
            $value["days"] = floor($time/86400);
            $time = ($time%86400);
            if ($time>=0){
                $value['days']++;
            }
        }
        $value['days'] = $value['days']."天";
        return implode($value);
    }

响应如下

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/940281.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-17
下一篇 2022-05-17

发表评论

登录后才能评论

评论列表(0条)

保存