function getBabyWeek(brithday) { if (isNaN(new Date(brithday))) { console.log('请输入正确格式的生日!'); return; } const babyTimes = new Date(brithday).getTime(); const nowTimes = new Date().getTime(); const gapYear = (nowTimes - babyTimes) / (365 * 24 * 60 * 60 * 1000); const year = parseInt(gapYear); const week = parseInt((gapYear - year) * 365 / 7); return `${year}岁${week}周龄`; } console.log(getBabyWeek('2020-13-28'));