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);
}
响应如下
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)