阳’);
const stemBranchResult = document.getElementById(‘stem-branch-result’);
const days = Math.floor((new Date() – new Date(1979, 10, 17, 0, 0, 0)) / 1000 / 60 / 60 / 24);
document.getElementById(‘days’).innerHTML = days;
queryButton.addEventListener(‘click’, () => {
const lunarDate = lunarDateInput.value;
const lunarDateArray = lunarDate.split(‘年’);
const year = parseInt(lunarDateArray[0], 10);
const month = parseInt(lunarDateArray[1].slice(0, 2), 10);
const day = parseInt(lunarDateArray[1].slice(2), 10);
const solarDate = new Date(year, month – 1, day, 0, 0, 0);
const dayOfWeek = [‘星期日’, ‘星期一’, ‘星期二’, ‘星期三’, ‘星期四’, ‘星期五’, ‘星期六’][solarDate.getDay()];
const zodiac = [‘猴’, ‘鸡’, ‘狗’, ‘猪’, ‘鼠’, ‘牛’, ‘虎’, ‘兔’, ‘龙’, ‘蛇’, ‘马’, ‘羊’][year % 12];
const constellation = [‘摩羯座’, ‘水瓶座’, ‘双鱼座’, ‘白羊座’, ‘金牛座’, ‘双子座’, ‘巨蟹座’, ‘狮子座’, ‘处女座’, ‘天秤座’, ‘天蝎座’, ‘射手座’][Math.floor(month – 1) % 12];
const stemBranch = [‘甲子’, ‘乙丑’, ‘丙寅’, ‘丁卯’, ‘戊辰’, ‘己巳’, ‘庚午’, ‘辛未’, ‘壬申’, ‘癸酉’, ‘甲戌’, ‘乙亥’, ‘丙子’, ‘丁丑’, ‘戊寅’, ‘己卯’, ‘庚辰’,’辛巳’, ‘壬午’, ‘癸未’, ‘甲申’, ‘乙酉’, ‘丙戌’, ‘丁亥’, ‘戊子’, ‘己丑’, ‘庚寅’, ‘辛卯’, ‘壬辰’, ‘癸巳’, ‘甲午’, ‘乙未’, ‘丙申’, ‘丁酉’, ‘戊戌’, ‘己亥’][year % 60 – 1];
lunarDateResult.innerHTML = lunarDate;
solarDateResult.innerHTML = `${solarDate.getFullYear()}年${solarDate.getMonth() + 1}月${solarDate.getDate()}日`;
dayOfWeekResult.innerHTML = dayOfWeek;
zodiacResult.innerHTML = zodiac;
constellationResult.innerHTML = constellation;
stemBranchResult.innerHTML = stemBranch;
});
|