📜  javascript 计算给定日期字符串的年龄 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:49.893000             🧑  作者: Mango

代码示例1
function getAge(dateString) {
   var ageInMilliseconds = new Date() - new Date(dateString);
   return Math.floor(ageInMilliseconds/1000/60/60/24/365); // convert to years
}
console.log(getAge('1997-04-23'));