这是我的代码,取自这里:Calculate age in JavaScript
var today = new Date();
birthday_val = $(".datepicker").val().split('/'); // input value
birthday = new Date(birthday_val[2],birthday_val[1],birthday_val[0]); // birthday date object
var age = today.getFullYear() - birthday.getFullYear();
var m = today.getMonth() - birthday.getMonth();
var d = today.getDay() - birthday.getDay();
if (m < 0 || (m === 0 && today.getDate() < birthday.getDate()) ) {
age--;
}
它计算正确,除了这一天 - 没有考虑到这一点,我不知道为什么。有接盘侠吗?