如何根据身份证号来计算年龄呢,这里我们使用PHP语言来计算下年龄,代码很简单。
<?php
function getAgesByID($id){
//过了这年的生日才算多了1周岁
if(empty($id)) return '';
$date=strtotime(substr($id,6,8));
//获得出生年月日的时间戳
$today=strtotime('today');
//获得今日的时间戳
$diff=floor(($today-$date)/86400/365);
//得到两个日期相差的大体年数
//strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
$age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;
return $age;
}
?>
方法很简单吧
关于本站 | 网站地图 | 手机版 | XML地图 | 反馈 | 版权申明 皖ICP备13006370号-1