let identityCard
= this.idNum
.replace(/\s+/g, "");
let len
= identityCard
.length
;
var strBirthday
= "";
if (len
== 18) {
strBirthday
=
identityCard
.substr(6, 4) +
"/" +
identityCard
.substr(10, 2) +
"/" +
identityCard
.substr(12, 2);
}
if (len
== 15) {
strBirthday
=
"19" +
identityCard
.substr(6, 2) +
"/" +
identityCard
.substr(8, 2) +
"/" +
identityCard
.substr(10, 2);
}
let birthDate
= new Date(strBirthday
);
let nowDateTime
= new Date();
var age
= nowDateTime
.getFullYear() - birthDate
.getFullYear();
if (
nowDateTime
.getMonth() < birthDate
.getMonth() ||
(nowDateTime
.getMonth() == birthDate
.getMonth() &&
nowDateTime
.getDate() < birthDate
.getDate())
) {
age
--;
}
console
.log(age
);
转载请注明原文地址: https://lol.8miu.com/read-22790.html