//获取出生日期 function getBirthday(cardNo) { var birthday = cardNo.substring(6, 10) + "-" + cardNo.substring(10, 12) + "-" + cardNo.substring(12, 14); return birthday; } //获取年龄 function getAge(cardNo) { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var age = year - cardNo.substring(6, 10) - 1; if (cardNo.substring(10, 12) < month || cardNo.substring(10, 12) == month && cardNo.substring(12, 14) <= day) { age++; } return age; } //获取性别 function getSex(cardNo) { var sex = ""; if(parseInt(cardNo.substr(16, 1)) % 2 == 1){ sex = "男"; } else { sex = "女"; } return sex; }
标签:10,12,cardNo,substring,date,身份证,var,出生日期,性别 From: https://www.cnblogs.com/sunline/p/17362369.html