/**
* 通过身份证号计算年龄
* @param {str} str 字符串 身份证号
*
*/
//iden参数是身份证号
function getAgeToIden(iden) {
let val = iden.length
let myDate = new Date()
let month = myDate.getMonth() + 1
let day = myDate.getDate()
let age = 0
if (val === 18) {
age = myDate.getFullYear() - iden.substring(6, 10) - 1
if (
iden.substring(10, 12) < month ||
(iden.substring(10, 12) == month && iden.substring(12, 14) <= day)
)
age++
}
return age
}
vue根据身份证号算出年龄
最新推荐文章于 2024-05-30 11:27:58 发布