• 根据身份证号,获取出生年月日,年龄,性别


    function discriCard(idCard){ 
        var user = {};
        //获取输入身份证号码 idCard
    
        //获取出生日期 
        idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14); 
        //获取性别 
        if (parseInt(idCard.substr(16, 1)) % 2 == 1) {
            //是男则执行代码 ...  
            user.sex = 2;
        } else { 
            //是女则执行代码 ... 
            user.sex = 1;
        } 
        //获取年龄 
        var myDate = new Date(); 
        var month = myDate.getMonth() + 1; 
        var day = myDate.getDate(); 
        var age = myDate.getFullYear() - idCard.substring(6, 10) - 1; 
        if (idCard.substring(10, 12) < month || idCard.substring(10, 12) == month && idCard.substring(12, 14) <= day) { 
            age++; 
        }
        //年龄 age 
        user.age = age;
        var birthday = "";  
            if(idCard != null && idCard != ""){  
                if(idCard.length == 15){  
                    birthday = "19"+idCard.substr(6,6);  
                } else if(idCard.length == 18){  
                    birthday = idCard.substr(6,8);  
                }  
              
                birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");  
            }  
        //出生日期
        user.birthday = birthday;
        return user;
    }
  • 相关阅读:
    Elasticsearch 深入5
    Elasticsearch 深入4
    Elasticsearch 深入3
    Elasticsearch 深入2
    Elasticsearch1简单深入
    Kibana简单操作Elasticsearch
    什么是非阻塞同步?
    面向对象之思考
    使用spring代码中控制事务
    mybatis 中使用oracle merger into
  • 原文地址:https://www.cnblogs.com/vendy/p/5687458.html
Copyright © 2020-2023  润新知