最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年12月11日 16:06:36   作者:china丶MRH  
這篇文章主要介紹了使用js獲取身份證年齡的示例代碼,幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下
 /**
 根據(jù)身份證號碼判斷性別
 15位身份證號碼:第7、8位為出生年份(兩位數(shù)),第9、10位為出生月份,第11、12位代表出生日
 18位身份證號碼:第7、8、9、10位為出生年份(四位數(shù)),第11、第12位為出生月份,
 第13、14位代表出生日期,第17位代表性別,奇數(shù)為男,偶數(shù)為女。
 */
 //根據(jù)身份證號獲取年齡
 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獲取身份證年齡的示例代碼的詳細內(nèi)容,更多關(guān)于js 獲取身份證年齡的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

叙永县| 峨眉山市| 睢宁县| 原平市| 肇东市| 开平市| 溧阳市| 宁津县| 麦盖提县| 松原市| 博客| 普安县| 合江县| 无锡市| 长治市| 工布江达县| 东辽县| 蒲城县| 固镇县| 乌苏市| 瑞金市| 康乐县| 内黄县| 斗六市| 新田县| 静海县| 平原县| 镇远县| 正镶白旗| 岑溪市| 石嘴山市| 黑山县| 原阳县| 贺州市| 沙河市| 彭泽县| 正宁县| 广平县| 绥芬河市| 湛江市| 丰都县|