Python 农历&公历日期转换

Python 农历&公历日期转换

  • 安装Borax
  • pip install borax
from borax.calendars.lunardate import LunarDate
today = LunarDate.today()
# 显示农历今日,即 七月初四
today

LunarDate(2020, 7, 4, 0)

today.animal
today.year
today.month
today.day

‘鼠’
2020
7
4

today.to_solar_date()

datetime.date(2020, 8, 22)

# 构建一个农历日期
today = LunarDate(2020,8,14,0)
today

LunarDate(2020, 8, 14, 0)

# 公历转农历,哦也,今年的国庆是八月十五
today=LunarDate.from_solar_date(2020,10,1)
today

LunarDate(2020, 8, 15, 0)

查询下每年公历10月1号的农历日期是中秋八月十五的年份

for i in range(100):
    theday = LunarDate.from_solar_date(2000+i,10,1)
    if theday.month==8 and theday.day==15:
        pass
        #years_count= theday.year-2014
        print(theday)
        #years_count

LunarDate(2001, 8, 15, 0)
LunarDate(2020, 8, 15, 0)
LunarDate(2031, 8, 15, 0)
LunarDate(2077, 8, 15, 0)

你可能感兴趣的:(Python,python,农历,农历公历,农历转换,阴历日期)