根据日期计算年龄

let d = new Date(val)//生日val:1999-01-01

let t = d.getTime(d) // 转换为时间戳

var t1 = Date.parse(new Date());//获取当前时间戳

let t2 = t1 - t;//计算时间戳之差

t2 = t2 / 1000 / (60 * 60 * 24 * 30 * 12)//将差值转换为年

t2 = Math.floor(t2)//向下取整

this.entityForm.age = t2;

console.log(t2);

 

 

 

来源:https://www.cnblogs.com/qiangyanhuanxiao/p/14651782.html

posted @ 2022-02-22 13:35  埃菲尔上的加菲猫  阅读(106)  评论(0编辑  收藏  举报