1. 程式人生 > >javascript根據生日計算年齡

javascript根據生日計算年齡

var birthday=new Date("1989-06-25".replace(/-/g, "\/")); 
var d=new Date(); 
var age = d.getFullYear()-birthday.getFullYear()-((d.getMonth()<birthday.getMonth()|| d.getMonth()==birthday.getMonth() && d.getDate()<birthday.getDate())?1:0);
alert(age);
http://hi.baidu.com/liuspring/item/bd1509cf2d1cff16b77a2402