国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

使用js獲取身份證年齡的示例代碼

瀏覽:142日期:2024-04-10 08:27:09

/** 根據(jù)身份證號(hào)碼判斷性別 15位身份證號(hào)碼:第7、8位為出生年份(兩位數(shù)),第9、10位為出生月份,第11、12位代表出生日 18位身份證號(hào)碼:第7、8、9、10位為出生年份(四位數(shù)),第11、第12位為出生月份, 第13、14位代表出生日期,第17位代表性別,奇數(shù)為男,偶數(shù)為女。 */ //根據(jù)身份證號(hào)獲取年齡 GetAge(identityCard) { let len = (identityCard + '').length; let strBirthday = ''; if (len == 18) { //處理18位的身份證號(hào)碼從號(hào)碼中得到生日和性別代碼 strBirthday = identityCard.substr(6, 4) + '/' + identityCard.substr(10, 2) + '/' + identityCard.substr(12, 2); } if (len == 15) { let birthdayValue = ''; birthdayValue = identityCard.charAt(6) + identityCard.charAt(7); if (parseInt(birthdayValue) < 10) { strBirthday = '20' + identityCard.substr(6, 2) + '/' + identityCard.substr(8, 2) + '/' + identityCard.substr(10, 2); } else { strBirthday = '19' + identityCard.substr(6, 2) + '/' + identityCard.substr(8, 2) + '/' + identityCard.substr(10, 2); } } //時(shí)間字符串里,必須是“/” let birthDate = new Date(strBirthday); let nowDateTime = new Date(); let age = nowDateTime.getFullYear() - birthDate.getFullYear(); //再考慮月、天的因素;.getMonth()獲取的是從0開(kāi)始的,這里進(jìn)行比較,不需要加1 if ( nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate()) ) { age--; } return age; }

以上就是使用js獲取身份證年齡的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于js 獲取身份證年齡的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 临海市| 句容市| 清远市| 平凉市| 隆昌县| 新乐市| 南雄市| 鄂伦春自治旗| 龙泉市| 榆社县| 耿马| 西城区| 双江| 阿拉善右旗| 汽车| 兰溪市| 洛浦县| 星子县| 海兴县| 栾川县| 资中县| 荆州市| 陆河县| 宾阳县| 林口县| 微山县| 织金县| 上林县| 松阳县| 灵寿县| 即墨市| 武强县| 大方县| 台安县| 广元市| 扬州市| 长武县| 建德市| 黄石市| 皋兰县| 西华县|