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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值