关于生日计算的程序

因为一个朋友要我帮忙改个javascript计算 他朋友孩子年龄的代码,发现其中有些难度,后来用php改写了程序,计算更准确些。

header ( "Content-type: text/html; charset=utf-8" );
 
$weeklist = array ("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" );
$date = date ( 'Y年m月d日' );
$dateDisp = $date . $weeklist [date ( w )];
 
echo '今天是' . $date . '<br>';
 
$birthday = strtotime ( '1977-02-14' ); //生日
$haveday = floor ( (time () - $birthday) / (60 * 60 * 24) ); //出生距离现在的天数
echo '生日是'.date('Y-m-d',$birthday).'<br>';
echo '距现在是'.$haveday.'天<br>';
 
//计算年
if (date ( 'n' ) >= date ( 'n', $birthday ) && date ( 'j' ) >= date ( 'j', $birthday ))
 $have_year = date ( 'Y' ) - date ( 'Y', $birthday );
else
 $have_year = date ( 'Y' ) - date ( 'Y', $birthday ) - 1;
 
//计算月 
if (date ( 'n' ) >= date ( 'n', $birthday )) {
 $have_month = date ( 'n' ) - date ( 'n', $birthday );
 
} else {
 if (date ( 'j' ) >= date ( 'j', $birthday )) {
  $have_month = 4 + date ( 'n' );
 } else {
  $have_month = 4 + date ( 'n' ) - 1;
 }
}
 
if (date ( 'j' ) >= date ( 'j', $birthday )) {
 $have_day = date ( 'j' ) - date ( 'j', $birthday );
} else {
 $time_tmp = time () - date ( 'd' ) * 86400;
 $date_tmp = date ( 't', $time_tmp );
 $have_day = $date_tmp - date ( 'j', $birthday ) + date ( 'j' );
}
 
echo '您'.$have_year . '岁' . $have_month . '月零' . $have_day . '天啦 ^_^';
//echo $haveday;