function getAnalysisIdCard(card, num) {
if (num == 1) {
//获取出生日期
let birth = card.substring(6, 10) + "-" + card.substring(10, 12) + "-" + card.substring(12, 14);
return birth;
}
if (num == 2) {
//获取性别
if (parseInt(card.substr(16, 1)) % 2 == 1) {
//男
return "男";
} else {
//女
return "女";
}
}
if (num == 3) {
//获取年龄
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - card.substring(6, 10) - 1;
if (card.substring(10, 12) < month || card.substring(10, 12) == month && card.substring(12, 14) <= day) {
age++;
}
return age;
}
}
/** 小程序或VUE框架加入下面这句*/
module.exports = {
getAnalysisIdCard: getAnalysisIdCard
}
原文地址:https://www.cnblogs.com/Mr-lin66/p/11441148.html
时间: 2024-11-01 10:34:14