//npm下载库
npm install lunar-calendar
// 公历日期转农历
const lunarDate = LunarCalendar.solarToLunar(2023,10,25);
console.log('公历日期转农历',lunarDate);
console.log('公历日期转农历',lunarDate.zodiac,lunarDate.GanZhiYear,lunarDate.GanZhiMonth,lunarDate.GanZhiDay,lunarDate.lunarMonthName,lunarDate.lunarDayName);
// 农历日期转公历
const solarDate = LunarCalendar.lunarToSolar(lunarDate.lunarYear, lunarDate.lunarMonth, lunarDate.lunarDay);
console.log('农历日期转公历',solarDate);
//返回结果
公历日期转农历 {
zodiac: '兔',
GanZhiYear: '癸卯',
GanZhiMonth: '壬戌',
GanZhiDay: '丙辰',
worktime: 0,
term: undefined,
lunarYear: 2023,
lunarMonth: 10,
lunarDay: 11,
lunarMonthName: '九月',
lunarDayName: '十一',
lunarLeapMonth: 2,
solarFestival: undefined,
lunarFestival: undefined
}
公历日期转农历 兔 癸卯 壬戌 丙辰 九月 十一
农历日期转公历 { year: 2023, month: 10, day: 25 }
分享一个前端农历和公历日期相互转换的库
最新推荐文章于 2024-04-12 11:09:47 发布