《PHP實(shí)例:php簡(jiǎn)單計(jì)算年齡的方法(周歲與虛歲)》要點(diǎn):
本文介紹了PHP實(shí)例:php簡(jiǎn)單計(jì)算年齡的方法(周歲與虛歲),希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
本文實(shí)例講述了php簡(jiǎn)單計(jì)算年齡的方法.分享給大家供大家參考,具體如下:PHP應(yīng)用
/** * $date是時(shí)間戳 * $type為1的時(shí)候是虛歲,2的時(shí)候是周歲 */ 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; }
PS:本站還提供了一個(gè)Unix時(shí)間戳轉(zhuǎn)換工具,包含了各種常見語(yǔ)言針對(duì)時(shí)間戳的操作方法,提供給大家參考:PHP應(yīng)用
Unix時(shí)間戳(timestamp)轉(zhuǎn)換工具:
http://tools.jb51.net/code/unixtimePHP應(yīng)用
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php日期與時(shí)間用法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》PHP應(yīng)用
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助.PHP應(yīng)用
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/2483.html