获取农历日期
lunar是一个支持阳历、阴历、佛历和道历的日历工具库,它开源免费,有多种开发语言的版本,不依赖第三方,支持阳历、阴历、佛历、道历、儒略日的相互转换,还支持星座、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等
python示例
安装
uv add lunar_python
from datetime import datetime
from lunar_python import Lunardef get_lunar_date():"""获取农历日期"""lunar = Lunar.fromDate(datetime.today())result = {"yearZhCn": lunar.getYearInChinese(),"yearGanZhi": lunar.getYearInGanZhi(),"yearShengxiao": lunar.getYearShengXiao(),"monthZhCn": lunar.getMonthInChinese(),"monthGanZhi": lunar.getMonthInGanZhi(),"dayZhCn": lunar.getDayInChinese(),"dayGanzhi": lunar.getDayInGanZhi(),}s = f"""{result["yearZhCn"]}年{result["monthZhCn"]}月{result["dayZhCn"]} {result["yearGanZhi"]}({result["yearShengxiao"]})年{result["monthGanZhi"]}月{result["dayGanzhi"]}日"""print(s)return resultif __name__ == "__main__":get_lunar_date()