使用 chinese-lunar-calendar npm 包进行公历与农历的相互转换。
首次使用需安装依赖:
bash
cd /tmp && npm install chinese-lunar-calendar
bash
# 查询公历日期对应的农历
node -e "
const { getLunar } = require('/tmp/node_modules/chinese-lunar-calendar/src/lunar_calendar.js');
const result = getLunar(2024, 1, 15);
console.log('公历 2024-01-15 => 农历:', result.lunarYear + result.lunarMonth + '月' + result.lunarDate + '日');
console.log('完整信息:', JSON.stringify(result, null, 2));
"
返回字段说明:
lunarYear - 农历年(甲子年格式,如"癸卯年")lunarMonth - 农历月份lunarDate - 农历日期isLeap - 是否闰月zodiac - 生肖solarTerm - 节气(如有)dateStr - 简写(如"腊月初五")农历节日公历参考(2024年)春节2024-02-10元宵节2024-02-24清明节2024-04-04端午节2024-06-10中秋节2024-09-17重阳节2024-10-11
用户: "今天农历几号?"
bash
# 获取今天日期
node -e "
const { getLunar } = require('/tmp/node_modules/chinese-lunar-calendar/src/lunar_calendar.js');
const today = new Date();
const result = getLunar(today.getFullYear(), today.getMonth() + 1, today.getDate());
console.log('今天是农历: ' + result.lunarYear + result.lunarMonth + '月' + result.lunarDate + '日 (' + result.zodiac + '年)');
"
用户: "2024年春节是哪天?"
bash
# 春节是农历正月初一
# 反查:2024年正月初一对应的公历
# 已知2024年春节是2024-02-10
echo "2024年春节: 2024-02-10 (癸卯年正月初一)"