直接根据天数计算会出现闰年问题

var birthday=new Date("1977-02-01".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);

标签: none

添加新评论