//从身份证号码中提取出生年月日,判断是否当天生日
export function extractBirthday(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 isTodayBirthday(birthday) {
var today = new Date();
var birthDate = new Date(birthday.replace(/-/g, "/"));
return today.getMonth() === birthDate.getMonth() && today.getDate() === birthDate.getDate();
}
//使用方法
//var idCard = '37082xxxxxxx2317';
//var extractedBirthday = extractBirthday(idCard);
//console.log("出生日期:", extractedBirthday);
//var isBirthday = isTodayBirthday(extractedBirthday);
//if (isBirthday) {
// console.log("今天是生日!");
//} else {
// console.log("今天不是生日。");
//}
js文件导出方法,身份证号码中提取出生年月日并判断是否当天生日
于 2024-03-26 09:39:39 首次发布