根據身份證號碼獲取出生日期
阿新 • • 發佈:2020-12-22
技術標籤:JavaScript
const getBirthdayByIdNO=(IdNO:string)=>{ let birthday = ""; if (IdNO.length===18) { birthday = IdNO.substr(6,8); return birthday.replace(/(.{4})(.{2})/,"$1-$2-"); }; if(IdNO.length===15){ birthday = "19"+IdNO.substr(6,6); return birthday.replace(/(.{4})(.{2})/,"$1-$2-"); }; return ""; };
const birthDay = getBirthDayByIdNO('652324198912300046');
console.log('birthDay',birthDay);