public function test()
{
$code = "340342198810113712";
$calculateAge = $this->calculateAge($code);
if($calculateAge >= 55){
return "到55";
}else{
return "不到55";
}
}
//计算年龄
public function calculateAge($code)
{
$date = strtotime(substr($code, 6, 8)); //获得出生年月日的时间戳
$today = strtotime('today'); //获得今日的时间戳
$diff = floor(($today - $date) / 86400 / 365); //得到两个日期相差的大体年数
//strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
$age = strtotime(substr($code, 6, 8) . ' +' . $diff . 'years') > $today ? ($diff + 1) : $diff;
$age = (int)$age;
return $age;
}
php 根据身份证计算年龄
最新推荐文章于 2023-12-25 16:19:38 发布