来源:未知 时间:2016-12-07 09:45 作者:xxadmin 阅读:次
[导读] php简单计算年龄的方法总结 /***$date是时间戳*$type为1的时候是虚岁,2的时候是周岁*/functiongetAgeByBirth($date,$type=1){$nowYear=date(Y,time());$nowMonth=date(m,time());$nowDay=date(d,time());$birthYear=date(Y,$date...
|
php简单计算年龄的方法总结 /**
* $date是时间戳
* $type为1的时候是虚岁,2的时候是周岁
*/
function getAgeByBirth($date,$type = 1){
$nowYear = date("Y",time());
$nowMonth = date("m",time());
$nowDay = date("d",time());
$birthYear = date("Y",$date);
$birthMonth = date("m",$date);
$birthDay = date("d",$date);
if($type == 1){
$age = $nowYear - ($birthYear - 1);
}else{$type == 2}{
if($nowMonth<$birthMonth){
$age = $nowYear - $birthYear - 1;
}elseif($nowMonth==$birthMonth){
if($nowDay<$birthDay){
$age = $nowYear - $birthYear - 1;
}else{
$age = $nowYear - $birthYear;
}
}else{
$age = $nowYear - $birthYear;
}
}
return $age;
}
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com