zoukankan      html  css  js  c++  java
  • JS中根据身份证号获取年龄、出生日期

    //获取年龄
    function GetAge(身份证号) {

    var strBirthday = "";
    if (len == 18)//18位身份证号
    {
    strBirthday = 身份证号.substr(6, 4) + "/" + 身份证号.substr(10, 2) + "/" + 身份证号.substr(12, 2);
    }
    if (len == 15)//15位身份证号

    {
    strBirthday = "19" + 身份证号.substr(6, 2) + "/" + 身份证号.substr(8, 2) + "/" + 身份证号.substr(10, 2);
    }

    //时间字符串里,必须是“/”隔开
    var birthDate = new Date(strBirthday);
    var nowDateTime = new Date();
    var age = nowDateTime.getFullYear() - birthDate.getFullYear();
    //月、天的因素;.getMonth()获取的是从0开始
    if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
    age--;
    }
    return age;
    }

    //获取出生日期

    //18位身份证号

    var birthday=身份证号.substr(6, 4) + "-" +身份证号.substr(10, 2) + "-" + 身份证号.substr(12, 2);

    //15位身份证号

    var birthday = "19" + 身份证号.substr(6, 2) + "/" + 身份证号.substr(8, 2) + "/" + 身份证号.substr(10, 2);

     
    小白的日常
  • 相关阅读:
    JS 随机整数
    微信小程序 功能函数 支付接口
    JS 正则表达式
    JS 日期 自动补齐 “2017-11-22 14:43”
    schema get_ddl
    StringBuffer 清空
    java中split任意数量的空白字符
    美国法官工资
    纪检委,检察院的工资
    国家司法机构
  • 原文地址:https://www.cnblogs.com/Stranger-WY/p/14015156.html
Copyright © 2011-2022 走看看