想要知道自己的年龄,出生日期和性别,或者是别人的,给我个身份证号,我就可以知道,看下面代码。static validateIdNumberToAgeYear(str){
let date = new Date();
let currentYear = date.getFullYear();
let currentMonth = date.getMonth() + 1;
let currentDate = date.getDate();
let idxSexStart = str.length == 18 ? 16 : 14;
let birthYearSpan = str.length == 18 ? 4 : 2;
let year;
let month;
let day;
let sex;
let birthday;
let age;
//性别
let idxSex = 1 - str.substr(idxSexStart, 1) % 2;
sex = idxSex == '1' ? '女' : '男';
//生日
year = (birthYearSpan == 2 ? '19' : '') + str.substr(6, birthYearSpan);
month = str.substr(6 + birthYearSpan, 2);
day = str.substr(8 + birthYearSpan, 2);
birthday = year + '-' + month + '-' + day;
//年龄
let monthFloor = (currentMonth