根据身份证获取生日日期

<html>
<head>
    <script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script>
    <script type="text/javascript">
        function getBirthdayFromIdCard(idCard) {
            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-");  
            }  
          
            return birthday;  
        }
        console.log(getBirthdayFromIdCard("410183198607175317"));

    </script>
</head>
<body>

</body>
</html>

 

posted @ 2019-06-28 16:29  大da脸  阅读(387)  评论(0编辑  收藏  举报