JS通过身份证号码获取出生年月日

这里我们讲述一下关于jq根据身份证号码计算出生日期、年龄、性别,有需要的同学可参考一下。
 
 代码如下 复制代码

//获取输入身份证号码 var UUserCard = $("#UUserCard").val(); //获取出生日期 //UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14); //获取性别 if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) { //男 } else { //女 } //获取年龄 var myDate = new Date(); var month = myDate.getMonth() + 1; var day = myDate.getDate();

var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1; if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) { age++; } //年龄 age

getBirthdayFromIdCard : function(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;
},

// 实例

425125198808083000

// 结果

1988-08-08

上一篇:C# Mysql You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ????


下一篇:出现个Expression(str != NULL)