一、可以计算周岁
getAge('1998-10-01')
getAge(val){
let currentYear = new Date().getFullYear() //当前的年份
let calculationYear = new Date(val).getFullYear() //计算的年份
const wholeTime = currentYear + val.substring(4) //周岁时间
const calculationAge = currentYear - calculationYear //按照年份计算的年龄
//判断是否过了生日
if (new Date().getTime() > new Date(wholeTime).getTime()){
return calculationAge
}else {
return calculationAge - 1
}
}