/** * refer: https://www.npmjs.com/package/solarlunar */ const solarLunar = require('solarlunar'); // 获取 今日 到 阳历指定日期 的间隔 function getSpanDays_solar(solarYear, solarMonth, solarDay) { let nowDate_00_00 = new Date(new Date().toLocaleDateString()); /* 当日0点 */ let festivalDayDate = new Date(`${solarYear}-${solarMonth}-${solarDay} 00:00:00`); let festivalSpanDays = ((festivalDayDate - nowDate_00_00) / (24 * 3600 * 1000)); // console.log(festivalSpanDays, nowDate_00_00, festivalDayDate); return festivalSpanDays; } // 获取 今日 到 农历指定日期 的间隔 function getSpanDays_lunar(lunarYear, lunarMonth, lunarDay) { let nowDate_00_00 = new Date(new Date().toLocaleDateString()); /* 当日0点 */ let festivalDay = solarLunar.lunar2solar(lunarYear, lunarMonth, lunarDay); // 农历 let festivalDayDate = new Date(`${festivalDay.cYear}-${festivalDay.cMonth}-${festivalDay.cDay} 00:00:00`); // 2022-09-09T16:00:00.000Z let festivalSpanDays = ((festivalDayDate - nowDate_00_00) / (24 * 3600 * 1000)); // console.log(festivalSpanDays, nowDate_00_00, festivalDayDate); return festivalSpanDays; } module.exports = { getSpanDays_solar, getSpanDays_lunar }