PHP根据生日计算年龄(周岁)
程序员文章站
2022-05-16 15:53:30
...
PHP根据生日计算年龄(周岁)
<?php/** * 根据时间戳计算年龄 * @param $birth * @return mixed */functionhowOld($birth) {list($birthYear, $birthMonth, $birthDay) = explode('-', date('Y-m-d', $birth)); list($currentYear, $currentMonth, $currentDay) = explode('-', date('Y-m-d')); $age = $currentYear - $birthYear - 1; if($currentMonth > $birthMonth || $currentMonth == $birthMonth && $currentDay >= $birthDay) $age++; return$age; } ?>
以上就介绍了PHP根据生日计算年龄(周岁),包括了方面的内容,更多相关内容请关注PHP中文网(www.php.cn)!
相关文章: