20,359
社区成员
发帖
与我相关
我的任务
分享
$no='431381197408191515';
$one=substr($no,6,8); //提权中间时间
$y=substr($one,0,4); //提权年
$m=substr($one,4,2); //提取月
$d=substr($one,6,2); //提取天
$all=$y.$m.$d; //完整的生日日期
//拿到的值是 1974-08-19
//然后把拿到的日期格式转换成时间戳
$two=strtotime($all); //但是这里又有问题哦,因为我后面没有具体的小时分钟
//然后就是当前日期减去拿到的时间戳,然后再换算
$alltime=time()-$two;
//下面的东西我就不会写了,
$no = '431381197408191515';
$year = substr($no, 6, 4);
$monthDay = substr($no, 10, 4);
$age = date('Y') - $year;
if ($monthDay > date('md')) {
$age--;
}
echo $age;
$no = '431381197408191515';
$year = substr($no, 6, 4);
$month = substr($no, 10, 2);
$day = substr($no, 12, 2);
$age = date('Y') - $year;
if ($month > date('m') || $day > date('d')) {
$age--;
}
echo $age;
$no='431381197408191515';
$one=substr($no,6,8); //提权中间时间
$y=substr($one,0,4); //提权年
$m=substr($one,4,2); //提取月
$d=substr($one,6,2); //提取天
$birth = $y.'-'.$m.'-'.$d;
echo getAge($birth);
/**
* 獲取年齡
* @param date $birth 日期
* @return int $age
*/
function getAge($birth) {
$mybirth = getdate(strtotime($birth));
$year = $mybirth['year'];
$month = $mybirth['mon'];
$day = $mybirth['mday'];
$ndate = getdate();
$nyear = $ndate['year'];
$nmonth = $ndate['mon'];
$nday = $ndate['mday'];
$age = $nyear - $year;
if (($nmonth * 100 + $nday) - ($month * 100 + $day) < 0) {
$age = $age - 1;
}
return $age;
}
42$no = '431381197408191515';
echo date('Y') - substr($no, 6, 4);
//足岁
echo date('Y') - substr($no, 6, 4) + (date('md') >= substr($no, 10, 4) ? 1 : 0);