查找自己农历生日与公历生日在同一天的年份

发布时间 2023-04-17 19:51:20作者: 不是豆豆
# 请先使用命令 pip install sxtwl 安装依赖库后,再执行以下脚本
import sxtwl ymc = ["", "", "", "", "", "", "", "", "", "" ,"", ""] rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] csn = 1990 # 出生年(公历) csgly = 1 # 出生月(公历) csglr = 1 # 出生日(公历) csrq = sxtwl.fromSolar(csn, csgly, csglr) csnly = csrq.getLunarMonth() # 出生月(农历,自动获取) csnlr = csrq.getLunarDay() # 出生月(农历,自动获取) czdns = 100 # 从出生年开始,遍历查找多少年 tytdcs = 0 # 记录同一天的次数 print("==================================================") for year in range(csn, csn + czdns): day = sxtwl.fromSolar(year, csgly, csglr) if day.getLunarMonth() == csnly and day.getLunarDay() == csnlr: tytdcs += 1 print("", tytdcs, "次,公历与农历生日在同一天") if((year - csn) == 0): print("我出生啦!") else: print("", (year - csn), "") print("公历:" + str(day.getSolarYear()) + "" + str(day.getSolarMonth()) + "" + str(day.getSolarDay()) + "") print("农历:" + ymc[day.getLunarMonth()-1] + "" + rmc[day.getLunarDay()-1]) print("==================================================")

参考来源:https://blog.csdn.net/m0_53623159/article/details/121843476

https://www.cnblogs.com/Eleven-Liu/p/11142703.html

https://pypi.org/project/sxtwl/