根据出生日期算出年龄
作者:互联网
根据出生日期换算年龄
getDate() {
// this.value = 2001-05-17 出生日期
var birthdays = new Date(this.value.replace(/-/g, "/"));
console.log(‘生日转换时间’,birthdays);
let d = new Date();
this.age = d.getFullYear() - birthdays.getFullYear() - (d.getMonth() < birthdays.getMonth() || (d.getMonth() == birthdays.getMonth() && d.getDate() < birthdays.getDate()) ? 1 : 0);
console.log('年龄', this.age)
}
标签:console,log,根据,birthdays,出生日期,年龄,getMonth,getDate 来源: https://blog.csdn.net/jie_ge_a/article/details/123065139