You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
998 B
35 lines
998 B
|
3 years ago
|
// 获取年月日等日期时间
|
||
|
|
function getDate() {
|
||
|
|
let myDate = new Date();
|
||
|
|
let month = myDate.getMonth() + 1;
|
||
|
|
let day = myDate.getDate();
|
||
|
|
return {myDate, month, day}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
//通过身份证号计算年龄、性别、出生日期
|
||
|
|
export const idCard = (userCard, num) => {
|
||
|
|
let birth
|
||
|
|
//获取出生日期
|
||
|
|
if (num == 1) {
|
||
|
|
birth = userCard.substring(6, 10) + "-" + userCard.substring(10, 12) + "-" + userCard.substring(12, 14);
|
||
|
|
return birth;
|
||
|
|
}
|
||
|
|
//获取性别
|
||
|
|
if (num == 2) {
|
||
|
|
if (parseInt(userCard.substr(16, 1)) % 2 == 1) {
|
||
|
|
return "男";
|
||
|
|
} else {
|
||
|
|
return "女";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//获取年龄
|
||
|
|
if (num == 3) {
|
||
|
|
let {myDate, month, day} = getDate()
|
||
|
|
let age = myDate.getFullYear() - userCard.substring(6, 10) - 1;
|
||
|
|
if (userCard.substring(10, 12) < month || userCard.substring(10, 12) == month && userCard.substring(12, 14) <= day) {
|
||
|
|
age++;
|
||
|
|
}
|
||
|
|
return age;
|
||
|
|
}
|
||
|
|
}
|