处理身份证获取用户的年龄
作者:互联网
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; },
标签:idcard,substr,birthdays,用户,nowDay,获取,let,身份证,getMonth 来源: https://www.cnblogs.com/hsonglin/p/15923942.html