<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_23869"> 主要考虑到闰年的情况,如果有人出生在2.29,那么不是闰年则过了2.28将算上一岁 <br> <br> <br> <br> <br> <div class="blockcode"> <div id="code_Vcr"><ol> <li>function age($birth) {</li> <li> $age = array();</li> <li> //$now = date('Ymd');</li> <li> $now = "20110228";</li> <li> //分解当前日期为年月日</li> <li> $nowyear = (int) ($now / 10000);</li> <li> $nowmonth = (int) (($now % 10000) / 100);</li> <li> $nowday = $now % 100;</li> <li> </li> <li> </li> <li> //分解出生日期为年月日</li> <li> $birthyear = (int) ($birth / 10000);</li> <li> $birthmonth = (int) (($birth % 10000) / 100);</li> <li> $birthday = $birth % 100;</li> <li> </li> <li> $year = $nowyear - $birthyear;</li> <li> if ($birthmonth>$nowmonth){</li> <li> $year--;</li> <li> }else if($birthmonth==$nowmonth){</li> <li> if($birthday==29&&$birthmonth=2){</li> <li>/* if($nowyear>3200||($nowyear%3200==0&&$nowyear%172800==0)){</li> <li> if($birthday>$nowday){</li> <li> $year--;</li> <li> }</li> <li> }else if($nowyear==3200){</li> <li> if (($birthday>$nowday)&&$nowday!=28){</li> <li> $year--;</li> <li> }</li> <li> }else */</li> <li> if ($nowyear%400==0||(($nowyear%4==0)&&($nowyear%100!=0))){</li> <li> if($birthday>$nowday){</li> <li> $year--;</li> <li> }</li> <li> }</li> <li> }</li> <li> }</li> <li> </li> <li> return $year;</li> <li> </li> <li> </li> <li> </li> <li> </li> <li>}</li> </ol></div> <em onclick="copycode($('code_Vcr'));">复制代码</em> </div> </td></tr></table> <div id="comment_23869" class="cm"> </div> <div id="post_rate_div_23869"></div> <br><br>