export function getSex(idCard) { if (idCard.length === 15) { return ['女', '男'][idCard.substr(14, 1) % 2] } else if (idCard.length === 18) { return ['女', '男'][idCard.substr(16, 1) % 2] } return '' } export function getBirthday(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; }; // 出生日期转年龄 export function getAgeFun(value) { var birthdays = new Date(value.replace(/-/g, "/")); //value 是传入的值 var time = new Date(); //当前时间 var age = time.getFullYear() - birthdays.getFullYear() - (time.getMonth() < birthdays.getMonth() || (time .getMonth() == birthdays.getMonth() && time.getDate() < birthdays.getDate()) ? 1 : 0); return age; }