处理身份证获取用户的年龄
testAge(idcard ) {
let birthday;
let nowDay = new Date();
// birthday = idcard.substr(6,4)
let birthdayYaer = idcard.substr(6, 4);
let birthdayMonth = idcard.substr(10, 2);
let birthdayDay = idcard.substr(12, 2);
birthday = birthdayYaer + "-" + birthdayMonth + "-" + birthdayDay;
let birthdays = new Date(birthday.replace(/-/g, "/"));
let age =
nowDay.getFullYear() -
birthdays.getFullYear() -
(nowDay.getMonth() < birthdays.getMonth() ||
(nowDay.getMonth() == birthdays.getMonth() &&
nowDay.getDate() < birthdays.getDate())
? 1
: 0);
return age;
},

浙公网安备 33010602011771号