思路:
玩家未过生日(当前年 - 出生年 -1)
玩家已过生日(当前年 - 出生年)
let nowTime = new Date();//当前时间(暂且使用本地时间)
const nowTimeY = nowTime.getFullYear();//获得当前年
const nowTimeM = nowTime.getMonth() + 1;//获得当前月
const nowTimeD = nowTime.getDate();//获得当前日期
const birthTime = new Date(UserProcesser.instance.UserInfo.birthday * 1000);
const birthTimeY = birthTime.getFullYear();//获得出生年
const birthTimeM = birthTime.getMonth() + 1;//获得出生月
const birthTimeD = birthTime.getDate();//获得出生日期
let year = nowTimeY - birthTimeY;
if (nowTimeM < birthTimeM) {//未过生日当月
year = nowTimeY - birthTimeY - 1;
} else if (nowTimeM === birthTimeM) {//月份相等,判断日期
if (nowTimeD < birthTimeD) {//未过生日当天
year = nowTimeY - birthTimeY - 1;
}
}
return year;