久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

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

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

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

以上就是使用js獲取身份證年齡的示例代碼的詳細內容,更多關于js 獲取身份證年齡的資料請關注好吧啦網其它相關文章!

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 长葛市| 新津县| 德清县| 阜新市| 汶上县| 宜兴市| 元氏县| 崇信县| 阿城市| 太谷县| 潮州市| 龙井市| 定襄县| 苏州市| 西和县| 奉化市| 镇雄县| 凤山县| 内乡县| 太仓市| 张家口市| 余干县| 内乡县| 固镇县| 久治县| 鲁甸县| 海宁市| 灵丘县| 会同县| 锡林浩特市| 泰宁县| 四平市| 巴东县| 乌审旗| 涞源县| 麻江县| 许昌县| 始兴县| 佛学| 曲水县| 永春县|